if gameobject is active?

is there a script to check if an object is active or inactive?

something like

if ( gamaeObject =active) { then blah blah blah; }

3 Answers

3

As of Unity 4.0 gameObject.active is obsolete and is replaced by gameObject.activeSelf

Source:
http://docs.unity3d.com/Documentation/Manual/UpgradeGuide3540.html

You actually want to use gameObject.activeInHierarchy to get the same behavior as gameObject.active. See http://answers.unity3d.com/questions/543560/does-active-getter-default-to-activeself-or-to-act.html.

if (gameObject.active)

specifically. Im wanting to check if a certain gameobject is active, and then act upon whether it is on or off. like can i check if a gameobject with a tag is active?

Your original post shows that you already know how to evaluate a conditional and then act upon the result, so just do that, except with the conditional that Eric showed you.

the object im looking to access is froma separate gameobject. i need to know how to do something like if (gameobject.Deagle.Active) { act; }

Read this: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html.

Thanks Dude

You can use “GameObject.activeSelf”: The local active state of this GameObject.
Link: Unity - Scripting API: GameObject.activeSelf

if(GameObject.activeSelf)
{
	print("GameObject is Active");
}

And with the inactive objects??