我有一场团结一致的乒乓球比赛,进球后球永远不会停止
这是我用于球的脚本
public class Ball extends MonoBehaviour {
public var ballVelocity : float = 1000;
public var rb : Rigidbody;
public var isPlay : boolean ;
public var randInt : int;
var audioPong : AudioSource;
function Awake()
{
audioPong = GetComponent.<AudioSource>();
rb = gameObject.GetComponent(Rigidbody);
randInt = UnityEngine.Random.Range(1,3);
}
function FixedUpdate(){
if(Input.GetMouseButton(0) == true && isPlay == false) {
transform.parent = null;
isPlay = true;
rb.isKinematic = false;
if(randInt == 1){
rb.AddForce(new Vector3(ballVelocity, 0, 0));
}
if(randInt == 2){
rb.AddForce(new Vector3(-ballVelocity, 0, 0));
} }
}
function OnCollisionEnter(col : Collision) {
audioPong.Play();
}
}
最佳答案
尝试将 RigidBody 的 angularDrag 属性设置为某个值。请参阅the documentation了解更多信息。
关于javascript - 我有一场团结一致的乒乓球比赛,进球后球永远不会停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37376115/