I am trying to make a menu system for each GameObject, and when a GameObject is clicked it will close all other menus and open the one for that GameObject. I am using one script for this:
using UnityEngine;
using System.Collections;
public class BlockMenus : MonoBehaviour
{
Vector3 point;
public Transform block;
public GameObject activeBlock;
bool buttonActive = false;
bool activeBlockActive = false;
string hitObject = "";
void Update()
{
point = Camera.main.WorldToScreenPoint(block.position);
}
void OnMouseDown()
{
hitObject = this.gameObject.transform.tag;
buttonActive = !buttonActive;
activeBlockActive = !activeBlockActive;
activeBlock.SetActive(activeBlockActive);
}
void OnGUI()
{
if(buttonActive)
{
switch(hitObject)
{
case "mine":
GUI.Box(new Rect(((point.x) * (1.08f)), ((Screen.height - point.y) * (0.1f)), (Screen.width * (0.3f)), (Screen.height * (0.5f))), "");
GUI.Button(new Rect(((point.x) * (1.08f)), ((Screen.height - point.y) * (0.87f)), (Screen.width * (0.05f)), (Screen.height * (0.06f))), "Build Mine");
break;
}
}
}
}