- Home /
Deactivate children with .active = false
I have this script, that deactivates the weapon of the player at star. But it deactivates only the parent object, and not all the other children, so, some parts of the weapon are visible. Any help/example?
var weapon : GameObject;
var holdingaxe : boolean = false;
function Start ()
{
weapon.active = false;
}
function Update ()
{
if(holdingaxe)
{
weapon.active = true;
}
}
Answer by Xroft666 · Oct 24, 2012 at 08:12 PM
weapon.SetActiveRecursively(false)
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActiveRecursively.html
smirlianos, I think it is you who voted me.
Just a tip: go throw all your posted questions and make all the answers accepted, so every guy who helped you will appreciate you :)
Answer by sfc.itzhak · Oct 26, 2012 at 06:52 AM
as the one above me wrote
weapon.SetActiveRecursively(false)
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActiveRecursively.html
or
function Start () { SetActiveRecrusive(weapon,false);
}
public function SetActiveRecrusive(TheChild : GameObject , State :boolean) { thechild.active=state;
foreach (Transform child in transform) { SetActiveRecrusive(child ,State ); }
}
this will go over all the subchilds and you can do what ever you want
sfc
Your answer
Follow this Question
Related Questions
Why is my gameObject.Find("Spotlight").GetComponent.() not working? 3 Answers
Weapon Switching 2 Answers
Objects in object pool not reactivating. 1 Answer
Yield WaitForTrue? 1 Answer
The player disappears in the air 1 Answer