Files
VillageBuilder/Assets/Scripts/Resource.cs

71 lines
1.7 KiB
C#
Raw Normal View History

2026-06-11 17:30:53 +01:00
using UnityEngine;
public class Resource : MonoBehaviour
{
public enum ResourceType
{
Wood,
Stone,
Metal,
Money,
Population,
Food,
Building
2026-06-11 17:30:53 +01:00
}
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;
}
}