/// <summary> /// While zombie stays in a spawn area, increment zombieStuckTime. /// </summary> void OnTriggerStay(Collider collider) { if (collider.IsZombieCollider() && collider.GetComponent <ZombieStateHandler>().IsRunning) { var zombie = new StuckZombie { zombie = collider.gameObject, zombieStuckTime = Time.deltaTime, }; stuckZombiesAtSpawnHandler.StuckZombiesCollection.TryAddNewStuckZombieOrUpdate(zombie); } }
/// <summary> /// Try add a stuck zombie instance if not exists in collection, or update existing one. /// </summary> /// <param name="stuckZombie">StuckZombie instance to add or update.</param> public void TryAddNewStuckZombieOrUpdate(StuckZombie stuckZombie) { var zombie = stuckZombies.SingleOrDefault( x => x.zombie != null && x.zombie.name == stuckZombie.zombie.name ); if (zombie != null) { zombie.zombieStuckTime += stuckZombie.zombieStuckTime; return; } stuckZombies.Add(stuckZombie); }