public static EnemyOld GetClosestEnemy(Vector3 position, float maxRange) { EnemyOld closest = null; foreach (EnemyOld enemy in enemyList) { if (enemy.IsDead()) { continue; } if (Vector3.Distance(position, enemy.GetPosition()) <= maxRange) { if (closest == null) { closest = enemy; } else { if (Vector3.Distance(position, enemy.GetPosition()) < Vector3.Distance(position, closest.GetPosition())) { closest = enemy; } } } } return(closest); }
public static EnemyOld Create(Vector3 position) { Transform enemyTransform = Instantiate(GameAssets.i.pfEnemy, position, Quaternion.identity); EnemyOld enemyHandler = enemyTransform.GetComponent <EnemyOld>(); return(enemyHandler); }