Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Transform FindClosestEnemy() //ENEMY TARGETS A CLOSEST TOWER
- {
- List<MonsterController> totalEnemies = ListMaster.instance.enemies;
- if (totalEnemies.Count == 0)
- return null;
- float shortestDistance = Mathf.Infinity;
- MonsterController closestEnemy = null;
- foreach (MonsterController enemy in totalEnemies)
- {
- float distanceToEnemy = MathMaster.GetDistance(enemy.transform.position, transform.position);
- if (distanceToEnemy >= _statControl.GetCurrentFinalRange()) continue; //This prevents us from having targets out of range.
- if (distanceToEnemy >= shortestDistance) continue; //Enemy is farther away than our current closest so hes skipped and we repeat everything above.
- if (enemy.focusedBy >= enemy.focusedByCap) continue; //If the enemy is at a max focus cap he is skipped and we repeat everything above.
- shortestDistance = distanceToEnemy;
- closestEnemy = enemy;
- }
- if (closestEnemy)
- {
- closestEnemy.targetedByList.Add(_monsterControl);
- closestEnemy.focusedBy++;
- }
- if (!closestEnemy)
- return null;
- return closestEnemy.transform;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement