Coder
Coder

Reputation: 529

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 OBJECT"))

     {
        myObject.SetActive(true);
     }

Upvotes: 0

Views: 76

Answers (1)

Barış Çırıka
Barış Çırıka

Reputation: 1570

I dont understand your question well but, first of all if you want to use GUI you must do it in OnGUI function.

Like:

function OnGUI () {
     if (GUI.Button(new Rect(1120,930,100,50),"3D OBJECT"))
     {
        myObject.SetActive(true);
     }
}

By the way i strongly recommend you that: Use Unity UI for GUI purposes.

Upvotes: 1

Related Questions