Semi-Quick question about "LookAt" script after respawn.

Hi,

I am having a problem with my “Look at” type of script(JavaScript). It’s on a boat turret and it fires when it spawns as long as it can find the target tagged BoatTarget. It makes the turret on the boat look at the target as long as the target hasn’t been destroyed yet but as soon as the target gets destroyed and respawns the boat turret wont look at the target or fire anymore. I have a similar script on an enemy itself that works just fine, which leads me to believe that the target isn’t properly attatched to the prefab of the boat in the inspector(I thought it was in script but after the target respawns it doesn’t do anything). I can’t even assign it in the inspector because the prefab parent that the target is a child under doesn’t have a drop down arrow. I did it in the scene view (when “target” was a public variable) because thats the only place I could do it other than code and it doesn’t work there either. Here is the script im using:

private var target : GameObject;
var boatProjectile : GameObject;
var boatFp1 : GameObject;
var nextFire : float = 1;
var fireRate : float = 1.1;

function Update () 
{

	target = GameObject.FindWithTag("BoatTarget");
	if(!target)
	{
		return;
	}
	
	transform.LookAt(target.transform.position);
	if(Time.time > nextFire)
	{
		nextFire = Time.time + fireRate;
		Instantiate(boatProjectile, boatFp1.transform.position, boatFp1.transform.rotation);

	}
}

I would like an example of how to assign it or a work around if anyones got one rather than a sriaght answer so I can learn what I am doing wrong rather then do it and forget. But if thats all you got I wont turn it down. Thanks for the help!

Edit: The problem is that the target that is respawning is a clone that doens’t have everything on it that the one in the scene view does. How do i fix this if I already hit apply and drag and dropped the target back into the inspector prefab and it didn’t change the clone?

Are you sure the respawned target is getting tagged with “BoatTarget”?

You should be able to check in the inspector while the game is running (e.g., don’t maximize the game window, select the target and see if it’s tagged).

You probably need to do something like (in whatever script spawns new enemies):

var enemy:GameObject;
enemy = Instantiate(enemyPrefab, spawnPosition, spawnRotation);
enemy.tag = "BoatTarget";