public class BulletMove : MonoBehaviour { public float Speed = 5f; public Transform Fx; // Use this for initialization void Start () { //5秒後,刪除自己 Dest ...
public class BulletMove : MonoBehaviour {
public float Speed = 5f;
public Transform Fx;
// Use this for initialization
void Start () {
//5秒後,刪除自己
Destroy(gameObject, 5f);
}
// Update is called once per frame
void Update () {
//沿著自身z軸坐標系,移動
transform.Translate(-Vector3.forward * Speed * Time.deltaTime);
}
/// 剛剛接觸
/// <param name="other"></param>
private void OnTriggerEnter(Collider other) {
//子彈和隕石發生了碰撞
var stone = other.GetComponent<Stone>();
if (stone !=null) {
stone.Hit();
//銷毀自身
Destroy(gameObject);
if(Fx != null) {
//生成特效
Transform fx = Instantiate(Fx);
fx.position = transform.position;
//2秒後刪除自己
Destroy(fx.gameObject,2f);
}
}
}
}