RTS enemy AI problem (A* pathfinding Aron)

i handled many things. My robots follow the target . However , when i add a robot (dublicated or cloning prefab) the fourth robot does not go to the target. And my robot prefab includes Seeker.cs , AIFollow.cs and wayfinder.js which is designed by me. Here is my code:

var target : Transform;
var myPosition : Vector3;
var enemies : Transform[];


var yuru:boolean=true;

var mesafe:float;

function Start () 
{    
	
	GetEnemies();    
	//myPosition = transform.position;    
	target = FindClosest(enemies);
	mesafe=Vector3.Distance(target.position,transform.position);
}

function Update(){

	GetEnemies();
	//myPosition=transform.position;
	target=FindClosest(enemies);
	
	this.GetComponent("Seeker").StartPath(this.transform.position,target.position);
	
	

}

function GetEnemies () 
{    
		var enemyObjects = GameObject.FindGameObjectsWithTag("Target");    
		enemies = new Transform[enemyObjects.Length];    

		for (i = 0; i < enemyObjects.Length; i++) 
		{        	
				enemies[i] = enemyObjects[i].transform;    
		}
}

function FindClosest (targets : Transform[]) : Transform 
{    

		var closestDistance = (enemies[0].position - myPosition).sqrMagnitude;    
		var targetNumber = 0;    
		
		for (i = 1; i < targets.Length; i++) 
		{        
				var thisDistance = (enemies[i].position - myPosition).sqrMagnitude;        
				if (thisDistance < closestDistance) 
				{            
								closestDistance = thisDistance;            
								targetNumber = i;        
				}    
		}    
	return enemies[targetNumber];
}

i do not understant. Why the fourth robot does not go its target. ?:frowning:

Any help i will appriciate…

The obvious question is did you debug this? Is the target being set, does it have the other scripts needed to make it work? Is the Enemies array being filled? Are there any objects out there with the “Target” tag?

If the first 3 work correctly, then there is a fault in where this bot chooses something and goes after it.

Tests you can do. show the number of Enemies that it found during creation. Show the target it found during creation.

Verify that your “Seeker” script is working correctly

Isn’t diagnosing bugs fun?

i handled it. i handled it … i change the Max Paths Per Frame at the Run Time Settings… The problem is solved…