I need help with the GUI, and using it to click.

Looked up a similar question, and made a few edits, leaving me with this (By the way, there are lots of //'s, some because I just couldn’t find a solution to those lines. Ignore them…):

using UnityEngine;
using System.Collections;

public class Click : MonoBehaviour {

public Texture tex;
//public float GUItrialone = GUI.Button(350, 350, (10, 20 "Try!"))
bool        displayGUI = false;
void    OnGUI()
{
	if (!tex)
		Debug.LogError ("Really Dude? After all this, you forget a TEXTURE???");

	if (Input.GetMouseButtonUp(0))
	{
		Ray            ray = Camera.main.ViewportPointToRay(Camera.main.ScreenToViewportPoint(Input.mousePosition));
		RaycastHit    outinfo;
		
		if (Physics.Raycast(ray, out outinfo, Mathf.Infinity))
		{
			//TOUCH! Show GUI
			displayGUI = true;
		}
	}
	if (displayGUI == true)
	{
		(GUILayout.Button(tex));
	}
}

}

I got tons of errors whenever I put in something for the GUI. Please help. (Context on the project-I am creating a map with little pins, and whenever you click on a pin, it shows you/displays text in the fom of a button. When the button is clicked, it disappears.)

I am sort of a noob at this, so…

Thanks in advance!

EDIT:

So I did get some help, so now here’s my script:

using UnityEngine;
using System.Collections;

public class Click : MonoBehaviour {

public Texture tex;
//public float GUItrialone = GUI.Button(350, 350, (10, 20 "Try!"))
bool        displayGUI = false;
void    OnGUI()
{
	if (!tex)
		Debug.LogError ("Really Dude? After all this, you forget a TEXTURE???");

	if (Input.GetMouseButtonUp(0))
	{
		Ray            ray = Camera.main.ViewportPointToRay(Camera.main.ScreenToViewportPoint(Input.mousePosition));
		RaycastHit    outinfo;
		
		if (Physics.Raycast(ray, out outinfo, Mathf.Infinity))
		{
			//TOUCH! Show GUI
			displayGUI = true;
		}
	}
	if (displayGUI == true)
	{
		GUILayout.Button(tex);

		if (GUILayout.Button (tex)) 
		{
			displayGUI = false;
		}
	}

}

}

But when I do this, it creates 2 buttons, and if you click the bottom one, it goes away. I want this to create only 1 button, and then when THAT one is clicked, it goes away.

EDIT:*

The final answer helped fix it!

Hi,

Try replaceing

(GUILayout.Button(tex));

with

if(GUILayout.Button(tex))
{
  Debug.Log("button action");
}

Actually, it didn’t work.

Now, wherever I click, it shows the GUI.