//void OnUnitSpawned(Health health) //{ // Debug.Log("OnUnitSpawned -- Notified!"); // health.OnDeathListeners += OnUnitDied; //} void OnUnitDied(UnitDeathInfo unitDeathInfo) { // Do we need to check if unitDeathInfo.DeadUnitGO is a unit we care to // listen to? For example, only the player? Debug.Log("Alerted about unit death: " + unitDeathInfo.DeadUnitGO.name); }
void Die() { // I am dying for some reason. // We COULD do these manually here, but what happens if // we add, remove, or change how these systems work? // Play Death Sound // Spawn Explosion // Increase Score // Drop Loot // Instead, we want to allow other systems to "listen" for our // death, and be alerted when that happens. // Let all our listeners know that we have died! if (OnDeathListeners != null) { UnitDeathInfo udi = new UnitDeathInfo(); udi.DeadUnitGO = gameObject; OnDeathListeners(udi); } Destroy(gameObject); }