Other
PLEASE HELP ACTIVE SELVE NOT WORKING :)
ok i want to detect is a clone is active using a tag if (GameObject.FindGameObjectWithTag ("Medium").activeSelf) but the .activeSelf is not working and is not checking if the clone is active or not please i cannot go further into my game and i cant find anyone else with this error
//clone that are not active not register and skips the .activeself function ??
Answer by TBruce · Nov 19, 2016 at 10:03 PM
Take a look at the following snippet. I know it is a little more that you posted, but it will help you determine what the problem is.
if (GameObject.FindGameObjectWithTag ("Medium") != null)
{
GameObject go = GameObject.FindGameObjectWithTag ("Medium");
Debug.Log("Game object '" + go.name + "' is " + (go.activeSelf ? "active" : "inactive"));
if (go.activeSelf)
{
// do something here
}
}
else
{
Debug.Log("There are no game objects with the tag of 'Medium'");
}
Answer by studioAdam · Nov 19, 2016 at 10:03 PM
Hi @The_Cookie_Rooster. It's hard to tell without seeing more of your code and game but is the parent of your GameObject active? If not, this could be throwing you off. Perhaps try:
if(GameObject.FindGameObjectWithTag("Medium").activeInHeirarchy)
instead of activeSelf.
See the Unity docs here: https://docs.unity3d.com/ScriptReference/GameObject-activeInHierarchy.html
and here: https://docs.unity3d.com/ScriptReference/GameObject-activeSelf.html
I hope this helps.
Regards.
Follow this Question
Related Questions
Random.Range kepps returing the same value 1 Answer
[C#] Enum not working properly 2 Answers
Instantiate is not working in unity 5.6.4f1 0 Answers
More bullets spawning that allowed 0 Answers