public static void Update(this SoldierEgg egg) { if (!egg.behaviour.gameObject.activeInHierarchy) { return; } var nearestLair = egg.GetNearestLair(); if (Vector3.Distance(nearestLair.GetPosition(), egg.GetPosition()) < SoldierEggConstants.HATCH_MIN_DISTANCE_LAIR) { egg.hatchProgress += Time.deltaTime; if (egg.hatchProgress > SoldierEggConstants.HATCH_TIME) { SoldierExtension.Instantiate(nearestLair.owner, egg.GetPosition()); egg.Destroy(); } } }
public static Lair GetNearestLair(this SoldierEgg egg) { Lair nearestLair = null; foreach (var lair in Core.Get <GameManager>().lairs) { if (nearestLair == null || Vector3.Distance(lair.GetPosition(), egg.GetPosition()) < Vector3.Distance(nearestLair.GetPosition(), egg.GetPosition())) { nearestLair = lair; } } return(nearestLair); }