void OnPillarDestroyed(PillarHealth pillar) { ActivePillars.Remove(pillar); //When all pillars are destroyed game is over if (ActivePillars.Count <= 0) { GameOver(); } }
void OnPillarDestroyed(PillarHealth pillar) { m_ActivePillars.Remove(pillar); //when attacked pillar is destroyed find next if (pillar == m_Target) { FindTarget(); } }
void FindTargetBasedOnHealth() { bool findGreatest = m_TargetPrioritization == TargetPrioritization.GreatestHealth; float compValue = findGreatest ? float.MinValue : float.MaxValue; for (int i = 0; i < m_ActivePillars.Count; i++) { float health = m_ActivePillars[i].CurrentHealth; if (findGreatest ? health > compValue : compValue > health) { compValue = health; m_Target = m_ActivePillars[i]; } } }
void FindTargetBasedOnDistance() { bool findGreatest = m_TargetPrioritization == TargetPrioritization.Farthest; float compValue = findGreatest ? float.MinValue : float.MaxValue; for (int i = 0; i < m_ActivePillars.Count; i++) { float dist = (transform.position - m_ActivePillars[i].transform.position).sqrMagnitude; if (findGreatest ? dist > compValue : compValue > dist) { compValue = dist; m_Target = m_ActivePillars[i]; } } }
//TODO: Only for test. Change it to something normal... //Find closest target and start move private void FindTarget() { m_Target = null; if (m_ActivePillars.Count == 0) { return; } switch (m_TargetPrioritization) { case TargetPrioritization.Closest: case TargetPrioritization.Farthest: FindTargetBasedOnDistance(); break; case TargetPrioritization.GreatestHealth: case TargetPrioritization.LowestHealth: FindTargetBasedOnHealth(); break; } SetDestination(); }