adding and subtracting from arrays

It’s probly very simple but I’m trying to figure out how you add or subtract and compare elements in the array in if statements.

var items = new Array(2,0,0);

if(items[0] > 0) {



items[0]--;


}

So the question I have how must I rewrite this to get this to work? I’m trying to keep track of multiple items of each the player has. So when they go to use one or get one added to their inventory it will change which ever value it needs to in the array.

The problem here is that you are trying to treat the weird Unity ArrayLists like an inbuilt array. What you really need here is an actual array, not the badly-named ‘Array’ class.

var items : int[] = [2, 0, 0];

Now, the above code should work properly.