Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Question error CS1002: ; expected | Simple Error however i cant find it.

Discussion in 'Scripting' started by JustJP2K, Aug 24, 2020.

  1. JustJP2K

    JustJP2K

    Joined:
    Aug 24, 2020
    Posts:
    5
    I copied this piece of code to mess around with procedural generation however i cant find the flaw in the code. It should run unless im too stupid to even copy code correctly. Help would be much appreciated!
    Assets\MeshGenerator.cs(27,18): error CS1002: ; expected

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [RequireComponent(typeof(MeshFilter))]
    6. public class MeshGenerator : MonoBehaviour
    7. {
    8.     Mesh mesh;
    9.  
    10.     Vector3[] vertices;
    11.     int[] triangles;
    12.  
    13.     public int xSize = 20;
    14.     public int zSize = 20;
    15.  
    16.     void Start()
    17.     {
    18.         mesh = new Mesh();
    19.         GetComponent<MeshFilter>().mesh = mesh;
    20.  
    21.         CreateShape();
    22.         UpdateMesh();
    23.     }
    24.  
    25.     void CreateShape()
    26.     {
    27.         vertices new Vector3[(xSize + 1) * (zSize + 1)];
    28.  
    29.         for (int i = 0, z = 0; z <= zSize; z++)
    30.         {
    31.             for (int x = 0; x <= xSize; x++)
    32.             {
    33.                 vertices[i] = new Vector3(x, 0, z);
    34.                 i++;
    35.             }
    36.  
    37.         }
    38.     }
    39.  
    40.     void UpdateMesh()
    41.     {
    42.         mesh.Clear();
    43.  
    44.         mesh.triangles = triangles;
    45.         mesh.vertices = vertices;
    46.  
    47.         mesh.RecalculateNormals();
    48.     }
    49.  
    50.     private void OnDrawGizmos()
    51.     {
    52.         if (vertices == null)
    53.             return;
    54.  
    55.         for (int i = 0; i < vertices.Length; i++)
    56.         {
    57.             Gizmos.DrawSphere(vertices[i], .1f);
    58.         }
    59.     }
    60. }
    61.  
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    You are missing an equal sign at line 27.
    Code (CSharp):
    1. vertices = new Vector3[(xSize + 1) * (zSize + 1)];
    As someone who spends most of his time with procedural generation, i cannot really recommend it to beginners. It's probably one of the hardest topics in game development in general, and definitely the hardest way concerning world / map generation. Of course, if it interrests you i'm not telling you to do something else.
    But if this kind of problem can still hold you back i'd focus on getting the basics down before diving into more complex topics.
     
  3. JustJP2K

    JustJP2K

    Joined:
    Aug 24, 2020
    Posts:
    5
    thanks! yeah ill probably try some more simple stuff, it was just really intriguing for me