using UnityEngine; public class Resource : MonoBehaviour { public enum ResourceType { Wood, Stone, Metal, Money, Population, Food, Building } public ResourceType resourceType; public enum ResourceState { Full, Depleted } public ResourceState resourceState; [SerializeField] int maxResourceQuantity; private int curResourceQuantity; [SerializeField] private GameObject fullModel, depletedModel; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { curResourceQuantity = maxResourceQuantity; SetResourceModel(resourceState); } // Update is called once per frame void Update() { } private void SetResourceModel(ResourceState state) { switch (state) { case ResourceState.Full: fullModel.SetActive(true); depletedModel.SetActive(false); break; case ResourceState.Depleted: fullModel.SetActive(false); depletedModel.SetActive(true); break; } } public void RemoveResource(int amountToRemove) { curResourceQuantity -= amountToRemove; if(curResourceQuantity <= 0) { curResourceQuantity = 0; resourceState = ResourceState.Depleted; SetResourceModel(resourceState); } } public bool GetResourceState() { if(resourceState == ResourceState.Full) { return true; } else return false; } }