Hey unity people! I am trying to activate and deactive a character on gui button clicks.
I am using Npc.active = true/false; , but when I deactivate it it only freezes the person. When I try to reactive it it tells me that there's a null reference exception...
I wan't to be able to completely turn off/on (not destroy) the npc and its children just like you can in the inspector window when you check the button for the object.
I have tried using npc.SetActiveRecursively(true) and its not working either. What am I doing wrong?
I am calling 'npc' with this
function Page4() {
Buttons();
npc = GameObject.FindWithTag("NPCmain");
GUI.Box (Rect (200,480,500,105), Name +"'s Team");
if (GUI.Button(Rect(210, 496, 150,30), " recall person1 ")){
npc.transform.position = transform.position + transform.right * -4;
npc.transform.parent = transform;
npc.active = false;
}if (GUI.Button(Rect(210, 510, 150,30), " release person1 ")){
//npc.active = true;
npc.SetActiveRecursively(true);
npc.transform.parent = null;
}
This is part of a few on gui pages. I parent the npc to the main player so that when I move though different levels, they come with me. Any help is appreciated!
EDIT- I almost forgot, I need to beable to activate npcs that are already set to active = false at the start of the game if it is possible. Please help me out