49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
public class Resources : MonoBehaviour
|
|
{
|
|
private void Awake()
|
|
{
|
|
// if Instance is not null, but has a value that is not this
|
|
// version of the object, destroy this version because only
|
|
// one is allowed to exist.
|
|
// otherwise assign this version to Instance.
|
|
if(Instance != null && Instance != this)
|
|
{
|
|
Destroy(this.gameObject);
|
|
}
|
|
else
|
|
{
|
|
Instance = this;
|
|
}
|
|
}
|
|
// note that the setter is private, meaning that no other class can set this property
|
|
public static Resources Instance { get; private set; }
|
|
public enum ResourceTypes { Gold, Steel, Wood, Water };
|
|
public List<ResourceAmount> resourceAmounts;
|
|
// 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 ResourceAmount GetResourceAmount(ResourceTypes resource)
|
|
{
|
|
// 'r' holds the current ResourceAmount element from our list as we iterate through it...
|
|
return resourceAmounts.Find(r => r.resourceType == resource);
|
|
}
|
|
}
|
|
[System.Serializable]
|
|
public class ResourceAmount
|
|
{
|
|
public Resources.ResourceTypes resourceType;
|
|
public int resourceAmount;
|
|
}
|
|
|