I have a basic enemy AI set up in my open world game, and i was looking at scripts that respawn the enemy, and short term they seem to work well but the enemies just chase you until youre far enough away, which means you could just get all the enemies in a town and bring them into the sea and get far enough away so they would leave you alone, so my question is, is there any way to respawn an enemy after a while after it dies, but also after a time when you are far enough away from it?
var distanceTillRespawn : float;
var LookAtTarget : Transform;
function Shoot(){
var distance = Vector3.Distance(LookAtTarget.transform.position, transform.position);
if (distance >= distanceTillRespawn){
//your respawn function
}
}