Activeself (Read only): The active state of the object itself, which corresponds to whether its checkbox in Inspector is checked
Activeinhierarchy (Read only): Whether the object is active in the hierarchy. That is, to make this value true, the activeself state of this object and all its parent objects (and ancestral objects) is true.
An object is visible (not hidden) in the scene, so that not only its own activeself is true, but the activeself state of all its parent objects (and ancestral objects) is true.
Summarize:
The Activeinhierarchy state represents the actual active state of the object in the scene. It actually represents the activeself state of an object and all its ancestral objects. The activeself corresponds to whether the checkbox in the Inspector is checked
The Activeself state represents the Activeself state of the object itself, so when the object itself is activeself true, and the activeself state of all its ancestors is not all true, The Activeinhierarchy state of this object is false.
activeself== object itself
activeinhierarchy== the object itself and all its ancestral objects = = Whether the object actually activates in the scene
As for SetActive, the activeself state of the object itself is changed, so when an object setactive, it may not be activated in the scene because its ancestor object may be inactive.
setactiverecursively, changing the activeself state of the object itself and all its sub-objects, is equivalent to invoking setactive on the object itself and all its sub-objects.
Since setactiverecursively is obsolete (obsolete), the future will be removed, so when you set the active state of an object and all its sub-objects, you can call the method
void Deactivatechildren (Gameobject g, bool a) { g.activeself = A; foreach (Transform child in G.transform) { Deactivatechildren (Child.gameobject, a);} }
Advanced Skill:
Using Extension Method
public static class extensions{public static void Setactivateforallchildren (this gameobject go, bool state) { C2/>deactivatechildren (go, State); } public static void Deactivatechildren (Gameobject go, bool state) { go. SetActive (state); foreach (Transform go.transform) { Deactivatechildren (child.gameobject, State);} }}
Now, Can use the like:
Public class Mytest:monobehaviour {public Gameobject go;//with this for initializationvoid Start () { // Obsolete //go. Setactiverecursively (true); Go. Setactivateforallchildren (True);}}
Reference:
http://blog.csdn.net/czlilove/article/details/23827267
Unity 3.5 to 4.0 upgrade Guide Upgrade guides from Unity 3.5 to 4.0
Http://game.ceeger.com/Manual/UpgradeGuide3540.html
Unity gameobject.activeself, Gameobject.activeinhierarchy,gameobject.setactive and setactiverecursively