void OnTriggerExit(Collider other) { // Detect nearby leaving enemies // (Only collisions with selectables should be reported here) Attackable otherAtt = other.GetComponent <SelectableCtrl> ().att; if (this.IsEnemy(otherAtt)) { AttList.Remove(otherAtt); } }
void OnTriggerEnter(Collider other) { // Detect nearby approaching enemies // (Only collisions with selectables should be reported here) Attackable otherAtt = other.GetComponent <SelectableCtrl> ().att; if (this.IsEnemy(otherAtt)) { AttList.Add(otherAtt); // Detect nearby dying enemies otherAtt.CurrentHp .TakeUntilDestroy(gameObject) .TakeWhile(hp => hp > 0) .DoOnCompleted(() => AttList.Remove(otherAtt)) .TakeWhile(_ => AttList.Contains(otherAtt)) .Subscribe(); } }