Hi all -
So, I’m chopping away at my incremental game, being fairly new to Unity and all. For the sake of simplicity, let’s say I’ve got three primary resources (food, wood, and ore) that I store as public integers in GameController. I then have a number of buttons that I can click to spend these resources (e.g., build a house, research something, etc etc).
The idea is that these buttons are disabled when the player doesn’t have enough resources to do whatever it is that they do (e.g., if it costs 20 wood to build a house and the player has less than 20 wood, the button should not be interactable).
I can easily do this for a single button, but when I have to deal with hundreds of buttons and dozens of resources, this becomes completely overwhelming. I find myself thinking that a more generic solution should be possible but can’t think of one. Any ideas?
Here’s the generic version of the script I’m using - it would work wonderfully if there was only one resource and only one way to spend it. Maybe some way to pass into the function exactly which resources and requirements it should be referencing when determining whether the button is interactable or not?
public int resourceCount;
public Button myButton;
void Update()
{
CheckButtonStatus();
}
void CheckButtonStatus()
if (resourceCount >= 20) {myButton.interactable = true}
else if (resourceCount < 20) {myButton.interactable = false}