I’m after a script that can toggle or switch a proposed (PTPropLift) and existing (ExistingMaster) object and all of its children, on/off using a gui button.
I am under the impression it may be easier to achive if there are two seperate buttons for an On and Off state?
The proposal needs to be deactivated at startup and the colliders also need to toggle on/off with the relative objects
Any ideas? This is way beond my coding expertise and I have already wasted hours on this one so would much appreciate any input
EDIT: Actually even if its just a button press rather than a gui, that would do!
Please bear in mind - ABSOLUTE scripting virgin here
I believe that you have a far simpler solution for this. In your editor. Make a few new Layers. Assign your object, (and all of its children when the popup comes up) to that layer, then simply turn the layer off to hide them all.
Or you could just use something like. Now they will start off deactivated and when you press “f” they will activate, then if you press “f” again they will deactivate and so on.
var PTPropLift : GameObject;
var ExistingMaster : GameObject;
var active : boolean;
function Start(){
PTPropLift.SetActiveRecursively(false);
ExistingMaster.SetActiveRecursively(false);
active = false;
}
function Update(){
if(Input.GetKeyDown("f")){
if(!active){
PTPropLift.SetActiveRecursively(true);
ExistingMaster.SetActiveRecursively(true);
active = true;
}
else{
PTPropLift.SetActiveRecursively(false);
ExistingMaster.SetActiveRecursively(false);
active = false;
}
}
}
Glad you got it going. Just FYI, the reason “active” threw an error is probably because it’s a reserved word. Some words, like boolean, int, float etc. have a specific meaning in javascript or in this case Unityscript so they can’t be used as variable names. Not sure if that’s the case here, but could well be. You may have had a problem with the script name as well. Keep the script names simple and also different from any variable names that you’re using. I’ve managed to confuse Unity with that in the past.