- Home /
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
Answer by Scribe · Jun 10, 2013 at 04:00 PM
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
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Set npc to inactive when certain distance away from controller (script not working) 0 Answers
Scripting within a area in the game 1 Answer
How do i Instantiate a prefab with specific assests included 3 Answers
C# Instantiating a Gameobject with a Flat Sphere Collider 1 Answer