Need help with GUI and raycast...and gameobject I click on, I get the GUI to show up.

Like the title says, I need help-whenever I click on ANY gameobject, the GUI shows up. I want it so be so that whenever I click on a specific object, then and for ONLY that object, the GUI shows up. So if I click on any other gameobject or mesh, the GUI won’t show up. Here’s my script :slight_smile:

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)
	{
		if(GUILayout.Button(tex))
			displayGUI = false;
	}

}

}

Thank you in advance!

Try to retrieve the game object from the RaycastHit, like this:

if (Physics.Raycast(ray, out outinfo, Mathf.Infinity))
{
    if(outinfo.transform.gameObject.name == "your game object"){
        displayGUI = true;
    }
}