Strategy GUI for building information
Hello,
I am making a strategy game and I am having some issues making the building's UI assign properly. When the player click's certain building, a UI panel would open and show that building's information however with the code I made it does indeed instantiate the UI panel when the building is placed but once I place more building's and click on one, all of the UI panel's would open. Here's my code:
public GameObject infoPanelPrefab;
public GameObject infoPanelHolder;
public ResourcesList resources;
public InfoPanel infoPanel;
// bools
private bool buildingIsPlaced = false;
private bool infoPanelIsOn = false;
void Start()
{
resources = GetComponent<ResourcesList>();
infoPanel = GetComponent<InfoPanel>();
SpawnInfoPanelWhenBuildingIsPlaced();
}
void Update()
{
DisplayInfoPanelOnClick();
}
public void SpawnInfoPanelWhenBuildingIsPlaced()
{
infoPanelHolder = GameObject.FindGameObjectWithTag("InfoPanelHolder");
infoPanelPrefab = Instantiate(infoPanelPrefab, transform) as GameObject;
infoPanelPrefab.transform.SetParent(infoPanelHolder.transform, false);
infoPanel = gameObject.GetComponent<InfoPanel>();
}
public void DisplayInfoPanelOnClick()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Input.GetMouseButtonDown(0))
{
if(Physics.Raycast(ray, out hit))
{
if(hit.collider.tag == "Building")
{
infoPanelPrefab.SetActive(true);
}
else if(hit.collider.tag != "Building")
{
infoPanelPrefab.SetActive(false);
}
}
}
}
Can you give me some advice?
Your answer
Follow this Question
Related Questions
How to make a electric/energy system? 1 Answer
How to move camera in x-z axis only for RTS touch script for mobile ? 0 Answers
unity failed to re-package resources,failed to re-package resources 0 Answers
Astar movement implementation not working properly 0 Answers
tutorial how to make a build-up, development strategy game ? 0 Answers