protected virtual void Update(){ if (node.isAILearned) { if (myTarget == null) { try{ if (targetsInRange.Count > 0) { //TODO change this to be able to target strong/weak/first/last Unit u = targetsInRange [0]; while (u == null) { targetsInRange.RemoveAt (0); if (targetsInRange.Count > 0) { u = targetsInRange [0]; } else { throw new UnityException (); } } double z = node.calculateZ (u); node.lastZ = z; // Debug.Log(z); //Do AI animation if (z <=0) { //target is an enemy myTarget = u; }else if (z == 0) { //Randomly picks if unit is ally or enemy. int rand = UnityEngine.Random.Range (0, 2); if (rand == 0) { myTarget = u; } else { targetsInRange.Remove(u); } } else { //Target is an ally. Next update will find another target. targetsInRange.Remove(u); } } }catch(UnityException e){ //There were no more valid targets to check. } } } if (Time.time >= nextFireTime) { FireProjectile (); } }