void Click() { //The method returns true if our mouse is hovering over UI. We only want to cast our rays if we do not click on ui. if (!EventSystem.current.IsPointerOverGameObject()) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, rayLength, layermask)) { Debug.Log("You selected the " + hit.transform.name); // ensure you picked right object if (hit.transform.GetComponent <Planetholder>() != null) { Planetholder planetH = hit.transform.GetComponent <Planetholder>(); planetH.OnClick(); } else if (hit.transform.GetComponent <Moonholder>() != null) { Moonholder moonH = hit.transform.GetComponent <Moonholder>(); moonH.OnClick(); } } else { ui.HidePopup(); } } }
public void ShowPopup(Planetholder p) { PopupPanel.SetActive(true); PopupPanel.transform.GetChild(0).GetComponent <Text>().text = p.planet.name; ClearImgChildren(); var t = PopupPanel.transform.GetChild(2); foreach (Building b in p.planet.Buildings) { var txt = Instantiate(textPrefab) as GameObject; txt.transform.SetParent(t, false); txt.GetComponentInChildren <Text>().text = b.name; } }