Trying to open UI planes only when needed but the SetActive(true) just wont work? The script is attached to the camera and the UI is referenced through the Array, UI_Menus.
public class ControleScript : MonoBehaviour {
public GameObject[] UI_Menus;
void Awake () {
//Find, set and then hide UIs.
UI_Menus [0] = GameObject.Find ("CityPlane");
UI_Menus [0].SetActive (false);
}
void Update () {
RaycastHit _hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//When Obj is selected, clicked, get tag and show related UI
if (Physics.Raycast (ray, out _hit, 100) & Input.GetKeyDown (KeyCode.Mouse0)) {
switch (_hit.transform.tag){
case "City":
City ();
break;
}
}
}
//Function to open and get needed data for UI.
void City(){
UI_Menus [0].SetActive (true);
//Get Values
//Set Values
}
}
As far as I have read into this you only need the GameObject to be reference through the inspector or through Awake/Start and the code to be on a different object but nothing seems to be working?