The question is answered, right answer was accepted
for() function problem
Hello community! I've got some kind of problem I can't solve.
using UnityEngine;
using System.Collections;
public class Testing : MonoBehaviour {
public int vsize_x = 101;
public int vsize_z = 51;
public float tileSize = 1.0f;
// Use this for initialization
void Start () {
int numVerts = vsize_x + vsize_z;
Vector3[] vertices = new Vector3[numVerts];
Vector3[] normals = new Vector3[numVerts];
Vector2[] uv = new Vector2[numVerts];
int x, z;
for (z = 0; z < vsize_z; z++)
{
for (x = 0; x < vsize_x; x++)
{
Debug.Log(z * vsize_x + x);
vertices[z * vsize_x + x] = new Vector3(x * tileSize, 0, z * tileSize);
normals[z * vsize_x + x] = Vector3.up;
uv[z * vsize_x + x] = new Vector2((float)x / vsize_x, (float)z / vsize_z);
}
}
}
}
So, the problem, if i understands it right, is that for (z = 0; z < vsize_z; z++) {...} works only 3 times, because in Debug.Log(z vsize_x + x); I receive numbers from 0 - 152 and error IndexOutOfRangeException: Array index is out of range. And that's strange? because I hope to get at least 5151 without errors ))) I'll appreciate any help, to solve this mystery of mine)
Follow this Question
Related Questions
Unity update does not be called when lock screen 0 Answers
JointDriveMode is obsolete, any alternatives? 2 Answers
Tag calling is calling all my objects with the same tag 2 Answers
onEnable & onDisable & onCollision never get called i have no idea y ?! 1 Answer
How to rotate camera 90 degrees but still keep control orientation in 2.5d? 0 Answers