Bool[] Array index is out of range
I'm trying to check if a bool inside an array of bools is true or not. Somehow it doesn't let me reach any index of that array. (Array index is out of range)
The code relevant to the question:
foreach (OrderAttributes order in GameInfo.OrdersInGame) { if (order.PlayerAccess[this.Index]) {
//do something }
Inside this class:
public int Index;
Inside the OrderAttributes class:
public bool[] PlayerAccess;
Inside the GameInfo class:
public OrderAttributes[] OrdersInGame;
Btw, I set all of those booleans as true on the Unity inspector, but the size of the list is either 8 or 0 atm.
"Index out of range" means that you are trying to access a field in the list that doesn't exit. (think of having a book with 5 pages and you're trying to check page 8.. it simply doesn't exit)
So you're issue is with the "this.index" variable which seems to be wrong. So try having a look at that one.
Your answer
Follow this Question
Related Questions
how do i check if all booleans in an array are false? C# 2 Answers
How to inherit a boolean 2 Answers
List of Structs variable values not changing 1 Answer
Destroy a Prefab from an Array? (C#) 2 Answers
Error CS1061: Are you missing an assembly reference? 2 Answers