Files
TutorialRTS/Assets/Scripts/ResourceSource.cs

41 lines
885 B
C#
Raw Permalink Normal View History

2026-03-19 17:31:51 +00:00
using UnityEngine;
using UnityEngine.Events;
public enum ResourceType
{
Wood,
Stone,
Food
}
public class ResourceSource : MonoBehaviour
{
public ResourceType type;
public int quantity;
//events
public UnityEvent onQuantityChange;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void GatherResource(int amount, Player gatheringPlayer)
{
quantity -= amount;
int amountToGive = amount;
if(quantity < 0)
amountToGive = amount + quantity;
if(quantity <= 0)
Destroy(gameObject);
if(onQuantityChange != null)
onQuantityChange.Invoke();
2026-03-20 17:34:22 +00:00
gatheringPlayer.GainResouces(type, amountToGive);
2026-03-19 17:31:51 +00:00
}
}