S
S
Sergey Bezrukov2018-08-24 13:40:15
Arrays
Sergey Bezrukov, 2018-08-24 13:40:15

Unity gives error Array index is out of range?

Unity throws an error array index is out of range.
There are 2 arrays:

public int[] money = { 0, 0, 0 };
public Text[] moneyText = new Text[3];

When starting the game, the console gives this error and refers to this line: I tried to replace gameMode with 0, and see what happens, then referred to lines that have an array of money[] and others, the size of which is also 3. The gameMode variable itself during issuing this error is 2. What could be the matter?
moneyText[gameMode].text = money[gameMode] + "$";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-08-24
@Hrederik

The size of the array is less than the index you are accessing.
If you have these public fields in the MonoBehaviour successor - then I don't care about new - the unit will init what was saved in the object on which the script hangs. And there most likely 0 objects.
Check with the debugger and in the inspector (if MonoBehaviour).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question