Search Unity

Scripting Error!

Discussion in 'Scripting' started by unity_FUc_6LWWe7c3mw, Jun 8, 2021.

  1. unity_FUc_6LWWe7c3mw

    unity_FUc_6LWWe7c3mw

    Joined:
    Jan 1, 2021
    Posts:
    43
    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.
    Code (CSharp):
    1. //meshGenarator.cs
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6.  
    7. public static class meshGenerator
    8. {
    9.     public static void GenerateTerraiMesh(float[,] heigthMap)
    10.     {
    11.         int width = heigthMap.GetLength(0);
    12.         int heigth = heigthMap.GetLength(1);
    13.         float topLeftX = (width - 1) / -2f;
    14.         float topLeftZ = (heigth - 1) / 2;
    15.  
    16.         MeshData meshData = new MeshData(width, heigth);
    17.         int vertexIndex = 0;
    18.  
    19.         for (int y = 0; y < heigth; y++)
    20.         {
    21.             for (int x = 0; x < width; x++)
    22.             {
    23.                 meshData.vertecies[vertexIndex] = new Vector3(topLeftX + x, heigthMap[x, y], topLeftZ - y);
    24.                 meshData.uvs[vertexIndex] = new Vector2(x / (float)width, y / (float)heigth);
    25.  
    26.                 if (x < width -1 && y < heigth - 1)
    27.                 {
    28.                     meshData.AddTriangle(vertexIndex, vertexIndex + width + 1, vertexIndex + width);
    29.                     meshData.AddTriangle(vertexIndex + width + 1, vertexIndex + 1);
    30.                 }
    31.  
    32.                 vertexIndex++;
    33.             }
    34.         }
    35.  
    36.         return meshData;
    37.  
    38.     }
    39. }
    40.  
    41. public class MeshData
    42. {
    43.     public Vector3[] vertecies;
    44.     public int[] triangles;
    45.     public Vector2[] uvs;
    46.  
    47.     int triangleIndex;
    48.  
    49.     public MeshData(int meshWidth, int meshHeigth)
    50.     {
    51.         vertecies = new Vector3[meshWidth * meshHeigth];
    52.         uvs = new Vector2[meshWidth * meshHeigth];
    53.         triangles = new int[(meshWidth - 1) * (meshHeigth - 1) * 6];
    54.     }
    55.  
    56.     public void AddTriangle(int a, int b, int c)
    57.     {
    58.         triangles[triangleIndex] = a;
    59.         triangles[triangleIndex + 1] = b;
    60.         triangles[triangleIndex + 2] = c;
    61.         triangleIndex += 3;
    62.     }
    63.  
    64.     public Mesh CreateMesh()
    65.     {
    66.         Mesh mesh = new Mesh();
    67.         mesh.vertices = vertecies;
    68.         mesh.triangles = triangles;
    69.         mesh.uv = uvs;
    70.         mesh.RecalculateNormals();
    71.         return mesh;
    72.     }
    73.  
    74. }
    75.  
    76.  
    77. // // errors
    78.  
    79. //Schweregrad    Code    Beschreibung    Projekt    Datei    //Zeile    Unterdrückungszustand
    80. //Fehler    CS7036    Es wurde kein Argument angegeben, das dem //formalen Parameter "c" von "MeshData.AddTriangle(int, int, //int)" entspricht.
    81.  
    82. //Schweregrad    Code    Beschreibung    Projekt    Datei    //Zeile    Unterdrückungszustand
    83. //Fehler    CS0127    Da //"meshGenerator.GenerateTerraiMesh(float[*,*])" "void" //zurückgibt, darf auf ein Rückgabeschlüsselwort kein //Objektausdruck folgen.
    84.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    An ERROR! My goodness... and even worse... a ...

    Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The important parts of an error message are:
    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220
     
    eMsylf likes this.
  3. eMsylf

    eMsylf

    Joined:
    Mar 9, 2018
    Posts:
    10
    The first error seems to say that you're missing variable "c" in a line where you call AddTriangle.

    The error stems from line 29, where you're only assigning 2 variables. On line 28 you're assigning 3 properly.

    I don't quite understand the second error, I'm sorry.

    Might I also add that you have a typo in "GenerateTerraiMesh" because the "n" in "Terrain" is missing.
     
    unity_FUc_6LWWe7c3mw likes this.
  4. unity_FUc_6LWWe7c3mw

    unity_FUc_6LWWe7c3mw

    Joined:
    Jan 1, 2021
    Posts:
    43
    Thanks, it work yet!