[英]C# Array index is out of range but index is zero
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];
void Start () {
int n=0;
for(int l=0;l<=Laenge;l++)
{
for(int b=0;b<=Breite;b++)
{
if(b>1 || l<Laenge)
{
if(b%2 ==1)
{
Debug.Log(l);Debug.Log(b);Debug.Log(n+"f");
new_Ver[n]=new_Ver_s[l,b]; //this is the line where it says theres a bug.
new_UV[n]=new_UV_s[l,b];
n++;
}
}
}
}
它说:
IndexOutOfRangeException:数组索引超出范围
但debug表示所有indizes均为零。 是因为元素为空吗? 我如何轻松地在其中放东西? 如果我对二维数组做同样的事情,那没有问题。 我尝试了一些操作,并将new_Uv_s替换为空的vector3变量。 仍然是同样的错误。
您的代码注定要崩溃,因为您每次迭代都会增加n ,并且可能有50次迭代=>在某个点上n会超过 new_Ver数组的最后一个索引29 。
为什么将其大小设置为30?
如果您想要一些纬度,请使用100。:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.