- Home /
Question by
ChrisButler · Nov 15, 2012 at 02:38 AM ·
arrayrangeout
Array out of Range
This is weird, and I'm not sure what I'm doing wrong. When the script starts, i instance my array like follows:
int[,] board = new int[7,7];7];
But when I go to try and test the script, and update occurs, it gives me an array is out of range with the following code only
for (x=0;x<=7;x++)
{
for (y=0;y<=7;y++)
{
if (board[x,y]==0)
{
tempx=tempx+24;
}
if (board[x,y]==1)
{
GameObject disk = GameObject.CreatePrimitive(PrimitiveType.Sphere);
disk.transform.localScale = new Vector3(20,20,5);
disk.transform.localRotation = new Quaternion(0,0,962,0);
tempx=tempx+24;
}
if (board[x,y]==2)
{
GameObject disk = GameObject.CreatePrimitive(PrimitiveType.Sphere);
disk.transform.localScale = new Vector3(20,20,5);
disk.transform.localRotation = new Quaternion(0,180,962,0);
tempx=tempx+24;
}
}
tempy=tempy-24;
}
Now, ignoring the tempx and temp y (these are for positioning and currently aren't attached to anything else) I can't see any problems with setting up the array to update itself...help?
Comment
Best Answer
Answer by Eric5h5 · Nov 15, 2012 at 02:57 AM
Arrays are zero-indexed. If you declare a size of 7, then you cannot use 7, only 0-6.
Your answer
Follow this Question
Related Questions
Wierd Animation Bug 0 Answers
array problem index out of range ? why ? 2 Answers
Array out of its own range? 4 Answers
Array out of range 1 Answer