1、利用update(),每一帧移动一段距离,实现一直移动的效果。
如:
// Update is called once per frame
void Update () {
//向上飞
float outToMove = projectitleSpeed * Time.deltaTime;
transform.Translate (Vector3.up*outToMove);
//消失在视野,销毁
if (transform.position.y >= 6.15f)
Destroy (gameObject);
}
2、利用AddForce(),给物体一个作用力,以后在惯性下运动
void openFire(){
if (Input.GetMouseButtonDown (0)) {
Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
instance.AddForce(Vector3.forward * power);
}
}