**I already know the difference between GameObject variables and Object variables***
I spawn a player prefab. When the player jumps into a pit, I destroy the player.
When the player hits spacebar, I respawn the player prefab at the same location it was destroyed.
This is where I'm stumped. I have a "follow" script (see below) on my enemy prefab. The enemy normally follows the player with no problem...but after I've destroyed the player prefab 1 time, the script loses it's reference to the player prefab and the enemy no longer follows the player. How can I make the script below keep it's reference to the player target?
var target : Transform; //the enemy's target
var moveSpeed = 10; //move speed
var rotationSpeed = 310; //speed of turning
var myTransform : Transform; //current transform data of this enemy
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("aggro").transform; //target the player
}
function Update () {
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
I've already tried setting the "target" property of the script but it only allows me to use an "Object" variable. I can't seem to get anything other than a script to sit in the "Object" variable. Normally I just find a "GameObject" by tag and store it as a variable. That doesn't work when dealing with external scripts though. Any help is greatly appreciated. Thank you.