1
我有一个对象,我想通过GetTouch在一定的距离抛出。我的代码正在工作,但问题是当我多次触摸屏幕,对象也移动多次,我不想要的,无论我触摸或滑动屏幕多少次,我都希望我的对象只移动一次。这是我试过的一些东西。第一次触摸后明智的GetTouch
public class RealBallMove : MonoBehaviour {
public float speed;
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.touchCount >0 &&
Input.GetTouch(0).phase == TouchPhase.Ended || (Input.GetMouseButtonDown(0)))
{
//rb.AddForce(Vector3.forward * speed);
//rb.AddForce(Vector3.up * speed);
GetComponent<Rigidbody>().isKinematic = false;
GetComponent<Rigidbody>().AddForce (new Vector3(0.0f, 20.0f, 12.0f));
//Destroy (GetComponent<Rigidbody>());
}
} }
非常感谢。 –