So, I’m writing a resource manager for my game, and… I’m trying to get it to add some resources, however. It’s not working correctly.
using UnityEngine;
using System.Collections;
public class ResourceManager : MonoBehaviour {
public static int FOOD = 0, LUMBER = 1, STONE = 2, GOLD = 3;
public int[] playerResource = new int[10];
public static string[] RESOURCE_NAMES = {
"Food",
"Lumber",
"Stone",
"Gold"
};
// Use this for initialization
void Start () {
addResource (FOOD, 100);
addResource (LUMBER, 100);
addResource (STONE, 100);
addResource (GOLD, 75);
}
// Update is called once per frame
void Update () {
}
void addResource(int id, int amm) {
for(int i = 0; i < playerResource.Length; i++) {
string resource = RESOURCE_NAMES*;*
_ if(playerResource == id) {_
* Debug.Log (“Adding: " +amm+ " of " +resource+” to stock"); *
* }*
* }*
* }*
* void deductResource() {*
* }*
}
It’s Debugging that it’s adding 100 to food, lumber, stone, AND GOLD, when it should only be adding 75 to gold, and then throwing an array out of bounds error, and I can’t for the life of me, figure out why.