Good day,
i try to make an level generator in Unity.
But i had a error in my my code bzw. the mesh generator code for error and code see down bellow, i am dont know how to fix the problem.
Thanks in Advance.
//meshGenarator.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class meshGenerator
{
public static void GenerateTerraiMesh(float[,] heigthMap)
{
int width = heigthMap.GetLength(0);
int heigth = heigthMap.GetLength(1);
float topLeftX = (width - 1) / -2f;
float topLeftZ = (heigth - 1) / 2;
MeshData meshData = new MeshData(width, heigth);
int vertexIndex = 0;
for (int y = 0; y < heigth; y++)
{
for (int x = 0; x < width; x++)
{
meshData.vertecies[vertexIndex] = new Vector3(topLeftX + x, heigthMap[x, y], topLeftZ - y);
meshData.uvs[vertexIndex] = new Vector2(x / (float)width, y / (float)heigth);
if (x < width -1 && y < heigth - 1)
{
meshData.AddTriangle(vertexIndex, vertexIndex + width + 1, vertexIndex + width);
meshData.AddTriangle(vertexIndex + width + 1, vertexIndex + 1);
}
vertexIndex++;
}
}
return meshData;
}
}
public class MeshData
{
public Vector3[] vertecies;
public int[] triangles;
public Vector2[] uvs;
int triangleIndex;
public MeshData(int meshWidth, int meshHeigth)
{
vertecies = new Vector3[meshWidth * meshHeigth];
uvs = new Vector2[meshWidth * meshHeigth];
triangles = new int[(meshWidth - 1) * (meshHeigth - 1) * 6];
}
public void AddTriangle(int a, int b, int c)
{
triangles[triangleIndex] = a;
triangles[triangleIndex + 1] = b;
triangles[triangleIndex + 2] = c;
triangleIndex += 3;
}
public Mesh CreateMesh()
{
Mesh mesh = new Mesh();
mesh.vertices = vertecies;
mesh.triangles = triangles;
mesh.uv = uvs;
mesh.RecalculateNormals();
return mesh;
}
}
// // errors
//Schweregrad Code Beschreibung Projekt Datei //Zeile UnterdrĂĽckungszustand
//Fehler CS7036 Es wurde kein Argument angegeben, das dem //formalen Parameter "c" von "MeshData.AddTriangle(int, int, //int)" entspricht.
//Schweregrad Code Beschreibung Projekt Datei //Zeile UnterdrĂĽckungszustand
//Fehler CS0127 Da //"meshGenerator.GenerateTerraiMesh(float[*,*])" "void" //zurĂĽckgibt, darf auf ein RĂĽckgabeschlĂĽsselwort kein //Objektausdruck folgen.