Activating/Deactivating GameObject Not Working

I can’t seem to get my button to activate gameobject. At the moment, I have the gameobject deactivating in the scene, but my button doesn’t activate the gameobject. What am I’m missing in my coding? The script is currently not attach to the gameobject.

#pragma strict

public var myObject :GameObject;

    if (GUI.Button(new Rect(1120,930,100,50),"3D MODEL"))

    {
       myObject.SetActive(true);
    }

Your code looks fine from a glance. Just make sure you’ve set up myObject to point to a game object. Make sure your model dont have its children disabled. SetActive will only activate that game object, not its children. Also if a parent of that game object is disabled, it has priority and myObject will remain disabled in the heirarchy.

You could get that info like this:

print("active in heirarchy: " + myObject.activeInHierarchy);
print("active self: " + myObject.activeSelf);

If both say “true”, then either you have the wrong reference set up, or the objects children are inactive.

If active in heirarchy is false, a parent is disabled.

If you get an error message, you haven’t set up a valid gameobject reference for myObject.

I’m getting this error message. Currently, I have the script attached to my Unity GUI buttons. Maybe the On Click GameObject.SetActive is interfering with my script. Any suggestions? Thanks.

Prefab GameObject's can not be made active! (accumulator)
UnityEngine.GameObject:SetActiveRecursively(Boolean)

56732-onlick.jpg

make sure you drug it(and not a different object) into the inspector slot… it took me a long time to find out that is critical… in most cases ^^