How to if(Setactive)?

Good day, i makea game for mobile.
I want to Disable/Enable an Button when a integer is …, but when i they dont check so my idea was to check if the LevelSelection Panel is active and then do thinks. But i dont no how to make a if statemant for SetActive.
Thanks in Advance.

void Update()
{
Level4Buttons
}

    public void Level4Buttons()
    {
        if (GameObject.Find("Seite2").activeInHierarchy)
        {
            if (getNext.WhichLevel >= 4)
            {
                GameObject.Find("Level4-ButtonIsNotAcitve").SetActive(true);
                GameObject.Find("Level4-Button").SetActive(false);
                Debug.Log("You can Play LV.4");
            }
            else
            {
                {
                    GameObject.Find("Level4-ButtonIsNotAcitve").SetActive(false);
                    GameObject.Find("Level4-Button").SetActive(true);
                    Debug.Log("You didn´t can play LV.4");
                }
            }
        }
    }

First, don’t use GameObject.Find(). It is plagued with enough difficulties that if you google a bit you’ll instantly understand.

Second, your specific use above will never work for the simple reason that if you look in the documentation, you’ll see the following line:

"This function only returns active GameObjects."

Make public fields for your GameObject and drag them in, or use some other kind of dynamic late-locator pattern if pre-authoring it does not work.

But unless you really truly understand 100% of the costs and limitations of GameObject.Find() (again, review the documentation), do not use GameObject.Find().

1 Like

Ok, thanks but when i want to get my GamObject by a Script (Gamebject = Gameobject.Find), its dont work. i mean its because i had had it on a object that dont destroy on Load, did you know how to solve this problem?