gui button appear when clicking on an object

I want a java code that when click to an object in the game appear buttons Help!!!

var btnTexture : Texture;

function OnMouseDown(){

function OnGUI() {

if (Input.GetMouseButtonDown(1)){
if (!btnTexture) {
Debug.LogError(“Please assign a texture on the inspector”);
return;
}
if (GUI.Button(Rect(10,10,50,50),btnTexture))
Debug.Log(“Clicked the button with an image”);
if (GUI.Button(Rect(10,70,50,30),“Click”))
Debug.Log(“Clicked the button with text”);
}
}
}

Fixed it :wink:

var btnTexture : Texture;
var showButton : bool;

function OnMouseDown(){
	showButton = true;
}

function OnGUI() {

	if (showButton)
	{
		if (!btnTexture) {
			Debug.LogError("Please assign a texture on the inspector");
			return;
		}
		
		if (GUI.Button(Rect(10,10,50,50), btnTexture))
			Debug.Log("Clicked the button with an image");
		
		if (GUI.Button(Rect(10,70,50,30),"Click"))
			Debug.Log("Clicked the button with text");
	}
}

When you will click on this GameObject showButton variable will set true and button will be drawn in OnGUI cycle.

it works perfectly, thanks you save my live Patico!!!

I seem to have screwed something up adapting this… THe idea is for an “exit” button to appear with the hidden object, i.e. rendering at the same time. Any help?

renderer.enabled = false;
collider.enabled = false;

var showButton : bool;

function PlanetaryMaps () {
	renderer.enabled = true;
	collider.enabled = true;
	showButton = true;
}

function OnGUI () {
	if (GUI.Button (Rect (200, 200, 20, 50), "Exit")){
		SendMessage ("CloseMaps");
		renderer.enabled = false;
		collider.enabled = false;
		showButton = false;
}
}