- Home /
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; }
Answer by Eric5h5 · Jan 23, 2011 at 02:47 AM
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; }
Answer by Kmulla · Apr 04, 2014 at 02:01 PM
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.
@youblistermypaint 's answer is correct nowadays.
Answer by tkamruzzaman · Nov 21, 2015 at 07:05 AM
You can use "GameObject.activeSelf": The local active state of this GameObject. Link: http://docs.unity3d.com/ScriptReference/GameObject-activeSelf.html
if(GameObject.activeSelf)
{
print("GameObject is Active");
}
RA$$anonymous$$BITO use " ! " before the GameObject.activeSelf ex:
if(!GameObject.activeSelf)
{
}
Your answer
