Player Resources and Required Resources follow a similar pattern;
public struct RequiredResources
{
public Resource resource;
public int quantityRequired;
}
public class Resource : ScriptableObject
{
[SerializeField]
private string resourceName;
public string GetName() { return resourceName; }
[SerializeField]
public Sprite icon;
public Sprite GetIcon() { return icon; }
}
The resources available to the player are as follows;
Food, Gold, Wood, Stone
I wish to use a system like this so I can easily add more resources as needed. When a building is placed it has a list of resources required to build it, for example a house may cost;
Gold = 5
Wood = 3
With the code below this will loop through the resources and reduce the amount as required. Basically the amount the player has - the cost, then update the UI.
public void UseResources()
{
foreach (RequiredResources requiredResources in building.GetResources())
{
foreach (ResourceManager.PlayersResources resource in player.playersResources)
{
if (requiredResources.resource.Equals(resource.GetResourceType()))
{
resource.RemoveQuantity(requiredResources.quantityRequired);
}
}
}
}
However, before running this I want to check if the player even has enough resources. When I use a similar logic to return true and false, and the player has enough wood (true) but not enough gold (false), it will remove the amount for both. I am at such a loss as to a way to do this correctly.
Please help!