Hi everybody,
I created a mesh from code and now i want to loop it when i press a Button.
Here is the code how i fill my Array
#region vertices
for (int x = 0; x < (width * segWidth); x += segWidth)
{
for (int z = 0; z < (depth * segDepth); z += segDepth)
{
vertices.Add(new Vector3(x, 0, z));
vertices.Add(new Vector3(x + segWidth, 0, z));
vertices.Add(new Vector3(x, 0, z + segDepth));
vertices.Add(new Vector3(x + segWidth, 0, z + segDepth));
}
}
#endregion
It looks like this picture
It works fine on the X axis, it’s just the Z axis… and i don’t know what i’m doing wrong :S
Here’re some pictures to explain the example:
And the Error is the Z axis (see following pictures):
And here is my algorithm:
void GridHandler()
{
for (int v = 0; v <= m.vertices.Length - 1; v++)
{
if(m.vertices[v].x < 1)
{
#region X Negativ
try
{
if (m.vertices[v + 1].x < 1)
{
finalPos[v] = new Vector3(finalPos[v].x + (width * segWidth), 0, finalPos[v].z);
m.vertices[v] = finalPos[v];
}
}
catch
{
print("X Negativ Reset");
finalPos[v] = new Vector3(finalPos[v].x + (width * segWidth), 0, finalPos[v].z);
m.vertices[v] = finalPos[v];
}
#endregion
}
else if (m.vertices[v].x > (width * segWidth - 1))
{
#region X Positiv
try
{
if (m.vertices[v - 1].x > (width * segWidth - 1))
{
finalPos[v] = new Vector3(finalPos[v].x - (width * segWidth), 0, finalPos[v].z);
m.vertices[v] = finalPos[v];
}
}
catch
{
print("X Positiv Reset");
finalPos[v] = new Vector3(finalPos[v].x - (width * segWidth), 0, finalPos[v].z);
m.vertices[v] = finalPos[v];
}
#endregion
}
else if (m.vertices[v].z < 1)
{
#region Z Negativ
try
{
if (m.vertices[v + 2].z < 1)
{
finalPos[v] = new Vector3(finalPos[v].x, 0, finalPos[v].z + (depth * segDepth));
m.vertices[v] = finalPos[v];
}
}
catch
{
print("Z Negativ Reset");
finalPos[v] = new Vector3(finalPos[v].x, 0, finalPos[v].z + (depth * segDepth));
m.vertices[v] = finalPos[v];
}
#endregion
}
else if (m.vertices[v].z > (depth * segDepth - 1))
{
#region Z Positiv
try
{
if (m.vertices[v - 2].z > (depth * segDepth - 1))
{
finalPos[v] = new Vector3(finalPos[v].x, 0, finalPos[v].z - (depth * segDepth));
m.vertices[v] = finalPos[v];
}
}
catch
{
print("Z Positiv Reset");
finalPos[v] = new Vector3(finalPos[v].x, 0, finalPos[v].z - (depth * segDepth));
m.vertices[v] = finalPos[v];
}
#endregion
}
else
{
m.vertices[v] = finalPos[v];
}
}
}
PS: Can somebody show me how to Lerp this? Thx