I am building my space tower defense game (cliched!) and am running into a funny issue :) Allow me to explain the situation. I have multiple boxes that I am using as turret spawn points, and am using the built in onGUI button ability in Unity to create buttons. My current workflow :
If you click on a button, it gets checked as "clicked" (boolean), meanwhile the onGUI checks to see if "clicked" is true. If it is true, it takes the last position that the mouse was (on the box) and create a GUI button on top of it. Everything works great! I added some code to make it so I can change clicked to false when I right click, or press escape, so that someone can click on a spawnbox, get the turret selection gui button, and if they choose not to click on a button they can right click off to the side somewhere and cancel out of the selection.
This all works great! However, I am looking for a way to turn off the buttons on a given spawnbox when ANOTHER spawnbox is pressed. At the moment, if I click on multiple spawnboxes, it makes multiple instances of the selection buttons until I click on an option or I right click cancel.
My current way of dealing with this is a function inside each spawnbox that I call each time a spawnbox is clicked. It creates an array of all the spawnboxes, and for each one sets "clicked" to false, and it is called before the "clicked" property is set to true for the one box I have clicked.
This works, but creating an array with each click just to change one property seems kind of a waste of resources. Is there a more efficient way to get rid of these buttons if I click on another spawnbox?