Set npc to active in same position as previous npc (script not working)

Hello - I need one npc to walk forward, and after 13 seconds, to disappear and another npc to be set to active in the same position.

This is my script, but although the first npc is destroyed, the second one is instantiated at 0,0,0.

What am I doing wrong?

var zombie : GameObject;
var exoGrey : GameObject;
var characterPosition : Vector3;

function Start () {

zombie.SetActive (false);
exoGrey.SetActive (false);

}

function OnTriggerEnter () {


zombie.SetActive (true);


yield WaitForSeconds (13);

zombie.SetActive (false);

zombie.transform.position = characterPosition;

exoGrey.transform.position = characterPosition;

exoGrey.SetActive (true);

}

Thanks, Laurien

calling zombie.transform.position = characterPosition; sets zombie.transform.position to characterPosition

I think you want this the other way round as otherwise characterPosition will default to Vector3(0, 0, 0) and remain as that.

Also personally I would save the position before deactivating the object and set the position after activating the new one, though I’m not actually sure this is necessary.

End result to replace code from line 20:

characterPosition = zombie.transform.position;
zombie.SetActive (false);
exoGrey.SetActive (true);
exoGrey.transform.position = characterPosition;

Scribe