C# 加特效

时间:2021-12-04 05:10:55

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></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);                   

}                          

}