Here is some code. It's not all but I think its the important code:
public int Laenge = 10;
public int Breite = 10;
public Vector3[] new_Ver = new Vector3[300];
public Vector3[,] new_Ver_s = new Vector3[11,11];
public Vector2[] new_UV = new Vector2[300];
public Vector2[,] new_UV_s = new Vector2[11,11];
public int[] new_Tri = new int[300];
void Start () {
int n=0;
for(int l=0;l<=Laenge;l++)
{
int k = 0;
for(int b=0;b<=Breite;b++)
{
Debug.Log(l);Debug.Log(b);Debug.Log(n+"n");
if(l<Laenge || b<Breite)
{
Debug.Log(l);Debug.Log(b);Debug.Log(n+"n");
if(b%2 == 1)
{
Debug.Log(l);Debug.Log(b);Debug.Log(n+"n");
new_Ver[n]=new_Ver_s[l,b];
new_UV[n]=new_UV_s[l,b];
n++;
new_Ver[n]=new_Ver_s[1+l,1+b];
new_UV[n]=new_UV_s[1+l,1+b];
n++;
new_Ver[n]=new_Ver_s[1+l,b];
new_UV[n]=new_UV_s[1+l,b];
n++;
}
else
{
Debug.Log(l);Debug.Log(b);Debug.Log(n+"nl");
Vector3 pop = new_Ver_s[l,b];
Debug.Log(l);Debug.Log(b);Debug.Log(n);//All debug. logs are zero
new_Ver[n] = pop; //This is the line where it gives the error message : Array index is out of range.
new_UV[n]= pop;
Debug.Log(l);Debug.Log(b);Debug.Log(n);
n++;
pop = new_Ver_s[l,1+b];
new_Ver[n]=pop;
new_UV[n]=pop;
n++;
pop=new_Ver_s[1+l,b];
new_Ver[n]=pop;
new_UV[n]=pop;
n++;
Debug.Log(l);Debug.Log(b);Debug.Log(n+"neo");
}
Debug.Log(l);Debug.Log(b);Debug.Log(n+"n");
}
if(b>1 || l<Laenge)
{
Debug.Log(l);Debug.Log(b);Debug.Log(n+"fn");
if(b%2 ==1)
{
Debug.Log(l);Debug.Log(b);Debug.Log(n+"f");
new_Ver[n]=new_Ver_s[l,b];
new_UV[n]=new_UV_s[l,b];
n++;
new_Ver[n]=new_Ver_s[l+1,b];
new_UV[n]=new_UV_s[l+1,b];
n++;
new_Ver[n]=new_Ver_s[l+1,b-1];
new_UV[n]=new_UV_s[l+1,b-1];
n++;
}
else
{
Debug.Log(l);Debug.Log(b);Debug.Log(n+"f");
new_Ver[n]=new_Ver_s[l,b];
new_UV[n]=new_UV_s[l,b];
n++;
new_Ver[n]=new_Ver_s[l+1,b];
new_UV[n]=new_UV_s[l+1,b];
n++;
new_Ver[n]=new_Ver_s[l,b-1];
new_UV[n]=new_UV_s[l,b-1];
n++;
}
}
}
}
}
This is quite much code. The if Bracket where the comment is, is where it first runs trough but it stops in the line where the comment is. All debug.logs are zero. If some parts about the code are unclear just ask in the comments.
The question is why does it give me the error message. If I do something similar with a two dimensional array there is no problem. Is it because the elements are empty?
Full error message:
IndexOutOfRangeException: Array index is out of range. meshmut.Start () (at Assets/meshmut.cs:88)
Ok solved. The code is right. Unity3d did something wrong and i had to reset some stuff. Thank you all for showing some other mistakes.