SetActive(true) not working despite the GameObject being referenced?

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?

I think what’s happening is that your City() function isn’t being executed. Just to be sure, put some print statements inside and outside your function so you can know what’s happening at every part of the code. Also a couple of things I noticed. You are using the “&” operator instead of “&&”. You ought to be using “&&” when dealing with bools. You should also invert the positions of the raycast and the get key down conditions in your IF since you only want to raycast when the button was pressed. Right now you are doing raycast everyframe, even when the mouse isn’t pressed, which is a bit of a waste :stuck_out_tongue: