Hey there,
I was just wandering if anyone knows of a method or work around for creating a chequered board no matter what the index is.
For instance if i create my grid at an odd index it is fine, but even is not. I need a way to ignore this and just work either way.
for (int x = 0; x < levelSize.x; x++)
{
for (int y = 0; y < levelSize.y; y++)
{
matIndex++;
if (matIndex > 1)
matIndex = 0;
Vector3 blockPos = new Vector3(-levelSize.x / 2 + 0.5f + x, 0, -levelSize.y / 2 + 0.5f + y);
GameObject newBlock = Instantiate(block, blockPos, Quaternion.identity) as GameObject;
newBlock.GetComponent<Renderer>().material = materials[matIndex];
Debug.Log(matIndex);
yield return new WaitForSeconds(0.1f);
}
}
Now i know it works like this.
Loop index :: 0 1 2 3 4 5 6
my index :: 0 1 0 1 0 1 0
Loop index :: 7 8 9 10 11 12
my index :: 1 0 1 0 1 0
This works great 0 = white, 1 = Black
But if i go ahead and change it to this.
Loop Index :: 0 1 2 3 4 5 6 7
my index :: 0 1 0 1 0 1 0 1
Loop index :: 8 9 10 11 12 13 14 etc
my index :: 0 1 0 1 0 1 0
But as you can see this is a problem as now it is creating the same Black white pattern for the next part of the grid.
Any help here would be great, I feel like a dumbass for not being able to work this out.
Cheers
John