Unity3d 發射子彈腳本

 1 public float m_speed = 10;
 2 public float m_liveTime = 1;
 3 public float m_power = 1.0f;
 4 protected Transform m_transform;
 5 
 6 void Start() {
 7   m_transform = this.transform;
 8 }
 9 
10 void Update() {
11   m_liveTime -= Time.deltaTime;
12   if(m_liveTime <= 0) 
13  {
14     Destory(this.gameObject);
15   }
16   
17   m_transform.Translate(new Vector3(0, 0, -m_speed * Time.deltaTime));
18 }

m_speed 子彈的速度this

m_liveTime 子彈存活一秒時間spa

m_power 子彈威力是1code

m_liveTime -= Time.deltaTime;
12   if(m_liveTime <= 0) 
13  {
14     Destory(this.gameObject);
15   }一秒後 子彈自動銷燬複製子彈的代碼Instantiate(m_rocket, m_transform.position, m_transform.rotation);
相關文章
相關標籤/搜索