我寫了一個函數,可以從Unity3d中的網格中獲取三角形,但是我得到一個「數組超出範圍」的錯誤。這是功能:Unity3D:數組超出範圍
static Vector3[,] CreateTriangles(Mesh _mesh)
{
// In this function I make an 2d array and then I store the triangles in there.
int TTriangleAmount = _mesh.triangles.Length/3;
int TTrianglePoints = _mesh.triangles.Length;
int TTriangleSize = 3;
Vector3[,] TTriangleArray = new Vector3[TTriangleAmount,TTriangleSize];
for(int i = 0; i < TTrianglePoints ; i += TTriangleSize)
{
TTriangleArray[i,0] = _mesh.vertices[_mesh.triangles[i + 0]];
TTriangleArray[i,1] = _mesh.vertices[_mesh.triangles[i + 1]];
TTriangleArray[i,2] = _mesh.vertices[_mesh.triangles[i + 2]];
}
return TTriangleArray;
}
我似乎無法找出它爲什麼超出範圍。任何人都可以看到我犯的缺陷嗎?
在此先感謝!