Simple Array Issue

It’s a simple problem but it’s driving me bonkers. I’m making a a stat screen where you assign points to stats. The problem is I can’t seem to update the Stat. The code I use is:

  for (i=0; i < playerModStats.length; i++) {
			if(GUI.Button (Rect(Screen.width/2 - 100,150+(Stat *25),20,25),"+")) {
				if (pointsLeft > 0) {
					pointsLeft --;
					playerModStats[i] ++; //Seems to have issues with this line here.
					}
                                   }

and the error it produces is

Any help would be appreciated.

Use built-in arrays (“var foo = new int[10]”), or use "playerModStats += 1".
–Eric

I would start out by naming your stats. For example you could store an array of GUIStyles and name them in the inspector. Then iterate though that a array and print the names that you chose in the inspector. Like Such:

    public class PlayerAttributes : MonoBehaviour {
        
        public GUIStyle[ ] attributes;
   
        private void ShowAttributes() {
            GUILayout.BeginArea(new Rect(100,100,100,100));
            
            for (int idx = 0; idx < attributes.Length; idx++) {
                  GUILayout.Button(attributes[idx].name, attributes[idx]);
            }
            GUILayout.EndArea();
        }
        private void OnGUI() {  ShowAttributes(); }
    }

I didn’t chekc hte syntax or anything. just helping you out/getting you started. Happy programming !!

Thanks eric. That error is gone. Still a few issues but I think it might be just a byproduct of my disorganization so I’ll try what Lamp suggested and whip up some GUI styles tomorrow. See if that irons things out. Till then, cheers.