Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Neffy · May 03, 2014 at 06:24 AM · c#proceduralgenerationvoxel

Huge C# Procedural Generation Errors. Why?

Hello, I've been using a tutorial I found to create a voxel system for the roguelike I'm making. I just really don't know where I went wrong since I wrote the identical code. Should the script have been cut into multiple scripts or what?

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class PolygonGenerator : MonoBehaviour {
     //This first list contains every vertex of the mesh that we are going to render.
     public List<Vector3> newVertices = new List<Vector3>();
 
     //The triangles tell Unity how to build each section of the mesh joining the vertices.
     public List<int> newTriangles = new List<int>();
 
     //The UV list is unimportant right now but it tells Unity how the texture is aligned
     //on each polygon.
     public List<Vector2> newUV = new List<Vector2>();
 
     public List<Vector3> colVertices = new List<Vector3> ();
     public List<int> colTriangles = new List<int>();
     private int colCount;
 
     private MeshCollider col;
 
 
     //A mesh is made up of the vertices, triangles and UVs we are going to define,
     //after we make them up we'll save them as this mesh.
     private Mesh mesh;
 
     private float tUnit = 0.25f;
     private Vector2 tStone = new Vector2 (0, 0);
     private Vector2 tGrass = new Vector2 (0, 1);
 
     private int squareCount;
     
     // Use this for initialization
     void Start () {
 
         mesh = GetComponent<MeshFilter> ().mesh;
 
         float x = transform.position.x;
         float y = transform.position.y;
         float z = transform.position.z;
 
         GenTerrain ();
         BuildMesh ();
         UpdateMesh ();
 
         col = GetComponent<MeshCollider> ();
 
 
     }
 
     void GenSquare(int x, int y, Vector2 texture){
 
         newVertices.Add(new Vector3 (x, y, z));
         newVertices.Add(new Vector3 (x + 1, y, z));
         newVertices.Add (new Vector3 (x + 1, y - 1, z));
         newVertices.Add (new Vector3 (x, y - 1, z));
         
         newTriangles.Add (squareCount*4);
         newTriangles.Add ((squareCount*4)+1);
         newTriangles.Add ((squareCount*4)+3);
         newTriangles.Add ((squareCount*4)+1);
         newTriangles.Add ((squareCount*4)+2);
         newTriangles.Add ((squareCount*4)+3);
         
         newUV.Add (new Vector2 (tUnit * texture.x, tUnit * texture.y + tUnit));
         newUV.Add (new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y + tUnit));
         newUV.Add (new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y));
         newUV.Add (new Vector2 (tUnit * texture.x, tUnit * texture.y));
 
         squareCount++;
         }
 
     // Update is called once per frame
     void Update () {
     
         mesh.Clear ();
         mesh.vertices = newVertices.ToArray ();
         mesh.triangles = newTriangles.ToArray ();
         mesh.uv = newUV.ToArray (); //Post-Initial Script Addition
         mesh.Optimize ();
         mesh.RecalculateNormals ();
 
     }
     void UpdateMesh () {
 
         mesh.Clear ();
         mesh.vertices = newVertices.ToArray ();
         mesh.triangles = newTriangles.ToArray ();
         mesh.uv = newUV.ToArray (); //Post-Initial Script Addition
         mesh.Optimize ();
         mesh.RecalculateNormals ();
 
         squareCount = 0;
         newVertices.Clear ();
         newTriangles.Clear ();
         newUV.Clear ();
 
         Mesh newMesh = new Mesh ();
         newMesh.vertices = colVertices.ToArray ();
         newMesh.triangles = colTriangles.ToArray ();
         col.sharedMesh = newMesh;
 
         colVertices.Clear ();
         colTriangles.Clear ();
         colCount = 0;
 
         }
 
     void GenCollider(int x, int y,){
         //Top
         colVertices.Add (new Vector3 (x , y , 1));
         colVertices.Add (new Vector3 (x + 1 , y , 1));
         colVertices.Add (new Vector3 (x + 1 , y , 0));
         colVertices.Add (new Vector3 (x , y , 0));
 
         ColliderTriangles ();
 
         colCount++;
 
         //Bot
         colVertices.Add (new Vector3 (x , y -1 , 0));
         colVertices.Add (new Vector3 (x + 1 , y -1 , 0));
         colVertices.Add (new Vector3 (x + 1 , y -1 , 1 ));
         colVertices.Add (new Vector3 (x , y -1 , 1 ));
 
         ColliderTriangles ();
 
         colCount++;
 
         //Left
         colVertices.Add (new Vector3 (x , y -1 , 1));
         colVertices.Add (new Vector3 (x , y , 1));
         colVertices.Add (new Vector3 (x , y , 0 ));
         colVertices.Add (new Vector3 (x , y -1 , 0));
 
         ColliderTriangles();
 
         colCount++;
 
         //Right
         colVertices.Add (new Vector3 (x +1 , y , 1));
         colVertices.Add (new Vector3 (x +1 , y -1 , 1));
         colVertices.Add (new Vector3 (x +1 , y -1 , 0));
         colVertices.Add (new Vector3 (x +1 , y , 0));
 
         ColliderTriangles ();
 
         colCount++;
     }
 
 
         void ColliderTriangles(){
         colTriangles.Add (colCount*4);
         colTriangles.Add ((colCount*4)+1);
         colTriangles.Add ((colCount*4)+3);
         colTriangles.Add ((colCount*4)+1);
         colTriangles.Add ((colCount*4)+2);
         colTriangles.Add ((colCount*4)+3);
 
         colCount++;
     }
 
     public byte[,] blocks;
 
     
     void GenTerrain(){
         blocks=new byte[10,10];
         
         for(int px=0; px<blocks.GetLength(0); px++) {
             for(int py=0;py<blocks.GetLength(1);py++){
                 if(py==5){
                     blocks[px,py]=2;
                 } else if(py<5){
                     blocks[px,py]=1;
                 }
             }
         }
     }
 
     void BuildMesh(){
         for (int px=0; px<blocks.GetLength(0); px++) {
             for(int py=0;py<blocks.GetLength (1);py++){
 
                 //If the block is not air.
                 if(blocks[px,py]);
 
                 //GenCollider here, this will apply it.
                 //To every block other than air.
                 GenCollider (px,py);
 
                 if(blocks[px,py]==1){
                     GenSquare (px,py,tStone);
                         else if(blocks[px,py]==2{
                     GenSquare(px,py,tGrass);
                     }
     }//End air block check.
    }
   }
  }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · May 03, 2014 at 06:43 AM

There are problems...likely related to your transcription of the code. For example on line 109:

 void GenCollider(int x, int y,){

...the comma to the right of the 'y' should not be there. Fixing this problem reveals other issues. On line 193, you are missing the closing ')' for the 'if' statement. In addition there is some sort of bracketing trouble in this area. That is, an else much be associated with a fully bracketed ({}) 'if' statement, and there is no closing bracket on line 192. I suggest you reexamine your transcription in this area.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Neffy · May 03, 2014 at 06:56 AM 0
Share

I reviewed the code and did two things and now I'm down to a single parsing error on line 200, which is closing the entire script. What cold it be?

avatar image robertbu · May 03, 2014 at 07:57 AM 0
Share

Typically a parsing error is caused a missing '}' at the end of the file. If you cannot figure it out, edit your question above and insert your latest code. I'll take a look tomorrow morning.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Help in understanding Mesh Generation 1 Answer

Cube Voxel not working. Help please 1 Answer

Distribute terrain in zones 3 Answers

How would I change my procedurally generated map change cells if it detects cells are around it? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges