GUI box open on MouseButtonDown

Ok so i am having a problem. I am trying to make a GUI pop up when i click on a cube. I have it working as to were the cube is recognized when i click on it but the GUI never appears what am i doing wrong?

'private void OnGUI()
{
if(Input.GetMouseButtonDown(0))
{

		Debug.Log("Hit at " +hit.point);
		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		if(Physics.Raycast(ray, out hit))
		{
			
			if(hit.transform.name == "Cube")
			{
				Debug.Log("hit it");
				GUI.Box(new Rect(10,10,100,200), "Menu");
			
			}
		}
	}			
}`

Input.GetMouseButtonDown(0) only returns true for the single frame the button is pressed, so you code is working, but the GUI.Box() is only getting called for a single frame. You can fix the immediate problem by using Input.GetMouseButton() which return true for every frame the button is held down.

But you should consider moving the Raycast() to Update() and setting a flag. OnGUI() is usually called multiple times per frame, so you are doing multiple raycasts where only one is needed. In addition, if you are trying to tie a specific message to this cube, you can simplify things to:

public class Example : MonoBehaviour {
 
	private bool bShow = false;
	
	void OnGUI() {
	 	if (bShow)
	          GUI.Box(new Rect(10,10,100,200), "Menu");
     }
	
	void OnMouseDown() { bShow = true;  }
	void OnMouseUp()   { bShow = false; }
}