Onto lesson 2
This commit is contained in:
39
Assets/Scripts/ResourceSource.cs
Normal file
39
Assets/Scripts/ResourceSource.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user