Hi i have script below that finds closest enemy with Type(i dont know what is this type exactly).
I dont want it to find some enemies (when their health <= 0) thats why im trying to make this code work with findwithTAG instead of findobjectsofTYPE so i can untag enemie when i dont want it to find. How can i do that thanks.
private void RotateClosestEnemy()
{
//FİND CLOSEST ENEMY
distanceToClosestEnemy = Mathf.Infinity;
Enemy[] allEnemies = GameObject.FindObjectsOfType<Enemy>();
foreach (Enemy currentEnemy in allEnemies)
{
float distanceToEnemy = (currentEnemy.transform.position - this.transform.position).sqrMagnitude;
if (distanceToEnemy < distanceToClosestEnemy)
{
distanceToClosestEnemy = distanceToEnemy;
closestEnemy = currentEnemy;
}
}
Debug.DrawLine(this.transform.position, closestEnemy.transform.position);
//-----------------------------------------------------------------------------------------------
Quaternion lookRotation = Quaternion.LookRotation(closestEnemy.transform.position - transform.position);
//DÜŞMANLARA DÖNERKEN NE HIZDA DÖNCEĞİ ALTTAKİ KOD
lookRotation = Quaternion.RotateTowards(transform.rotation, lookRotation, 900*Time.fixedDeltaTime);
if (distanceToClosestEnemy < 135)
{
rb.MoveRotation(lookRotation);
}
}