using TMPro; using UnityEngine; public class FoodMakerController : MonoBehaviour { [SerializeField] private float foodMax = 50f; [SerializeField] private float foodRate = 1f; private float food; private TMP_Text foodIndicator; // Start is called before the first frame update private void Start() { food = 0f; foodIndicator = transform.Find("FoodIndicator").GetComponent(); } // Update is called once per frame private void Update() { food = Mathf.Clamp(food + foodRate * Time.deltaTime, 0f, foodMax); foodIndicator.SetText("Food:\n" + Mathf.FloorToInt(food)); } // called whenever the player collects the resources from this construct public float CollectAll() { var amount = food; food = 0f; return amount; } public void Disassemble() { Destroy(gameObject); } }