Hey, Im using a fairly cludge setup to turn on and off an object with a keypress and I was wondering if someone could help me refine it. Im certain that there are many overlaps with these two scripts that are unnecessary. However whenever I change this setup it never seems to work, I heard that it may have something to do with SetActiveRecursively () But I couldn’t get that method to quite work either.
This first script is placed on the object to be toggled disabled/enabled.
function Update () {
if (Input.GetKeyDown("p")) {
gameObject.active = !gameObject.active;
}
}
This script is placed on the first person controller.
var onoff : boolean;
var testObject : GameObject;
function Update () {
if(Input.GetKeyDown("p")){
if (onoff == true)
testObject.active = true;
if (onoff == false)
testObject.active = false;
}
}
Im very new to scripting and they appear to do the same thing, but they do not work without eachother. This is probably due to referencing an object that is disabled and one of the scripts being disabled when toggling. I would really appreciate some help with this matter please.