using UnityEngine; using System.Collections; /// <summary> /// 2014_3_26 修改 /// </summary> [AddComponentMenu("MyGame/RocketBase")] public class RocketBase : MonoBehaviour { //子弹的发射的间隔 public float _rate = 1; //子弹飞行的速度 public float _speed = 1; //子弹的生存时间/攻击范围 public float _liveTime = 2; //子弹的威力 public float _power = 1; //子弹的形态/子弹类型 //子弹的位置 protected Transform _transform;//protected只有派生类才能访问 //子弹在飞机上的位置 public enum PlaneTransform { Top,Left_Right,Bottom}; public PlaneTransform _planeT = PlaneTransform.Top; void Start() { _transform = this.transform; } void Update() { onLiveTime(); _transform.Translate(new Vector3(0, 0, _speed*Time.deltaTime));//现在子弹是以Z轴发射的 } void onLiveTime() { _liveTime -= Time.deltaTime; if (_liveTime < 0) { Destroy(this.gameObject);//当生命时间等于0时 消除自身 } } //这里应该定义一个子弹发射的方式,如直线向前或者是散弹 又或者是跟踪导弹之类的 }
原文:http://www.cnblogs.com/sy88/p/3624656.html