How do you create a GUI Button upon clicking a game object?

HI i am new to unity and especially new to unity's implementation of java, and i was wondering how i would go about creating a GUI button (4 or 5 of them) after the player clicks a game object.

currently i have an object with an empty game object inside of it set to is trigger. the radius is set to reach outside the parent object. i have 2 scripts attached to it one is for changing the cursor a different color when you are hovering over it (which works fine) the other is supposed to create the GUI buttons after the trigger is clicked.

i have tried going about this in a few ways. to me it seems like i need to use Input.GetMouseButtonDown(0)) but if i try to do it inside a ONGUI() the Buttons are there no matter what. i think this is because you need to call Input.GetMouseButtonDown(0)) in an Update()

so i guess my question is how do i call an update function and then a ONGUI function and get the result im looking for.

Any help at all is well received.

thanks

You don't need to use Input.GetMouseButtonDown inside OnGUI. You should set a boolean to true inside Update and check that boolean inside OnGUI.

Something like this:

var selected = false;

function OnMouseUp()
{
    selected = true;
}

function Update()
{
    if (Input.GetMouseButtonDown(0)) //user clicked somewhere else
    {
        selected = false;
    }
}

function OnGUI()
{
    if (selected)
    {
         if (GUI.Button("My Button"))
         {
             // button was clicked
         }
    }
}

The last Answer could not be quite accurate, cus it will show the GUI after clickin anywhere, not only on a game object

the idea of the boolean is correct, but you need code for validating the clicked gameobject

bool showGUIButton =false;
    void Update()
    {
       Ray ray = Camera.main.ScreePointToRay(Input.mousePosition);
       RaycastHit hit;
       if(Physics.Raycast(ray,out hit))
       {
          string whatihit = hit.transform.name;
          //here you can validate the name of what you hit, with the object that you need to  check if you hit it
          //eg.
          if(whatihit == "Player")
          {
             showGUIButton = true;
          }
       }
    }

void OnGUI()
{
   if(showGUIButton)
   {
      if(GUI.Button("Button"))
      {
         //code after the button is clicked
      }
   }
}

hope it helps you =)