Files
VillageBuilder/Assets/Scripts/UIController.cs

58 lines
1.7 KiB
C#

using UnityEngine;
using TMPro;
public class UIController : MonoBehaviour
{
public static UIController Instance;
[SerializeField] TextMeshProUGUI wood, stone, population;
void Awake()
{
Instance = this;
}
void Start()
{
UpdateStats();
}
public void UpdateStats()
{
wood.text = GameManager.Instance.GetResource(Resource.ResourceType.Wood).ToString();
stone.text = GameManager.Instance.GetResource(Resource.ResourceType.Stone).ToString();
population.text = GameManager.Instance.GetResource(Resource.ResourceType.Citizens).ToString();
}
// Called by left-clicking a JobButton
public void AddJob(NPC.Job jobToAssign)
{
NPC[] npcs = FindObjectsByType<NPC>(FindObjectsSortMode.None);
foreach(NPC npc in npcs)
{
// Find a Citizen and give them the new job
if(npc.job == NPC.Job.Citizen)
{
npc.SetJob(jobToAssign);
Debug.Log($"Assigned a Citizen to {jobToAssign}");
break; // Stop after assigning one
}
}
}
// Called by right-clicking a JobButton
public void RemoveJob(NPC.Job jobToRemove)
{
NPC[] npcs = FindObjectsByType<NPC>(FindObjectsSortMode.None);
foreach(NPC npc in npcs)
{
// Find an NPC currently doing this job and revert them to a Citizen
if(npc.job == jobToRemove)
{
npc.SetJob(NPC.Job.Citizen);
Debug.Log($"Removed a {jobToRemove} and made them a Citizen");
break; // Stop after removing one
}
}
}
}