Elegant solution for setting interactable to 'false' for numerous buttons

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}

Well, I might’ve solved it - instead of storing the value of each resource as a variable within one big script, I created a generic script called “resource” which has a public int quantity. I then created an interactability controller script as follows:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class InteractabilityController : MonoBehaviour {

    public Resource resource;
    public int requiredQuantity;

    // Update is called once per frame
    void Update () {

        if (requiredQuantity > resource.quantity)
            {
            GetComponent<Button>().interactable = false;
            }
        else
            {
            GetComponent<Button>().interactable = true;
            }
        }
}

The idea is that now I have a button prefab that I can make simply drag onto the screen, then drag onto it the resource that is required for the button to be active and its required amount. This makes adding new buttons a relatively painless existence, though I suspect there’ll be trouble down the line when I have to check for multiple resource requirements (should be easy) and for non-resource conditions that might influence whether the button is interactable (might be trickier).