Subversion Repository Public Repository

Nextrek

Diff Revisions 138 vs 139 for /3DSpace/Assets/Custum/Scripts/EnemyShip.cs

Diff revisions: vs.
  @@ -101,7 +101,6 @@
101 101
102 102 void Fire()
103 103 {
104 -
105 104 foreach (Vector3 _wmp in weaponMountPoints)
106 105 {
107 106 Quaternion small = Quaternion.Euler(Random.Range(-WEAPON_AIM,WEAPON_AIM),
  @@ -121,11 +120,25 @@
121 120 }
122 121 }
123 122
123 + GameObject _lastTarget = null;
124 + float _timer = 0;
125 + private static float CHANGE_TARGET_TIMER = 5000.0f;
126 +
124 127 void DoSmallShip()
125 128 {
126 - Transform spaceShip = GameManager.GetHero();//GameManager.Instance.spaceShip;
129 + //Transform spaceShip = GameManager.Instance.spaceShip;
130 + //if (spaceShip==null) return;
131 + _timer += Time.deltaTime;
132 +
133 + if ((_lastTarget == null) || (_timer > CHANGE_TARGET_TIMER))
134 + {
135 + _timer = 0;
136 + _lastTarget = GameManager.GetClosestShip(GameManager.ALLY_TAG, this.gameObject);
137 + }
138 +
139 + if (_lastTarget == null) return;
127 140
128 - if (spaceShip==null) return;
141 + Transform spaceShip = _lastTarget.transform;
129 142
130 143 if (isEnteringArea)
131 144 {
  @@ -144,7 +157,7 @@
144 157 /***
145 158 * Navigation routine
146 159 */
147 - float distance = Vector3.Distance(this.transform.position,spaceShip.position);
160 + float distance = Vector3.Distance(this.transform.position, spaceShip.position);
148 161
149 162 // The step size is equal to speed times frame time.
150 163 float step = ROTATION_SPEED * Time.deltaTime;