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 AntonPol2001 · Mar 02, 2014 at 01:19 PM · errorchunk

Error in code! Help me please! =(

Hello everyone, I'm new to c # and I can not understand the error code:

using UnityEngine; using System.Collections; using System.Collections.Generic;

public enum TerrainType { Lowlands, Highlands, Mountains }

[RequireComponent (typeof(MeshFilter))] [RequireComponent (typeof(MeshCollider))] public class Chunk : MonoBehaviour {

 public int height = 40;
 public int groundHeight = 8;
 public byte[,,] map; 
 
 protected Mesh mesh;
 
 protected List<Vector3> verts = new List<Vector3>();
 protected List<int> tris = new List<int>();
 protected List<Vector2> uv = new List<Vector2>(); 
 
 protected MeshCollider meshCollider;
 
 public List<GameObject> targets = new List<GameObject>();
 
 protected bool initialized = false;
 protected int width;
 
 
 
 // Use this for initialization
 void Start () {
     
     Terrain terrain = Camera.main.GetComponent<Terrain>();
     width = terrain.chunkSize;

     map = new byte[width, height, width];

     float baseTerrainHeight = GetGroundHeight(GetTerrainFor(transform.position.x, transform.position.z));

     float[,] terrainHeights = new float[3,3];

     for (int dx = -1; dx <= 1; dx++)
     {
         for (int dz = -1; dz <= 1; dz++)
         {
             float myX = transform.position.x + dx * width;
             float myZ = transform.position.z + dz * width;
             
             terrainHeights[dx + 1, dz + 1] = GetGroundHeight(GetTerrainFor(myX, myZ)) + baseTerrainHeight / 2;
         }
     }

     for (int x = 0; x < width; x++)
     {

         float xPercent = (float)x / (float)width;
         float xHeight1 = CurvePoint(xPercent, terrainHeights[0,0],terrainHeights[1,0],terrainHeights[2,0]);   
         float xHeight2 = CurvePoint(xPercent, terrainHeights[0,1],terrainHeights[1,1],terrainHeights[2,1]);   
         float xHeight3 = CurvePoint(xPercent, terrainHeights[0,2],terrainHeights[1,2],terrainHeights[2,2]);   

         for (int z = 0; z < width; z++)
             {
                 float zPercent = (float)z / (float)width;
                 float tileHeight = CurvePoint(xHeight1, xHeight2, xHeight3);
                 for (int y = 0; y < tileHeight; y++);

                 map[x, y, z] = 1;
             }
         }
     }

     
     /*
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < groundHeight; y++)
         {
             for (int z = 0; z < width; z++)
             {
                 map[x, y, z] = 1;
             }
         }
     }
     //*/

 for (int dx = -1; dx <= 1; dx++)
 {
     for (int dz = -1; dz <= 1; dz++)
     {
         float myX = transform.position.x + dx * width;
         float myZ = transform.position.z + dz * width;
         List<LandBrush> brushes = GetBrushesFor(myX, myZ); 
     }
     for (int a = 0; a < brushes.Count; a++) 
     {
         brushes[a].ApplyBrush(this);
     }
 }

} initialized = true; Regenerate();

}

 // Update is called once per frame
 void Update () {
 }
 
     public void CloseMeshTarget()  {
     
     mesh.vertices = verts.ToArray();
     mesh.triangles = tris.ToArray();
     mesh.uv = uv.ToArray();
     mesh.RecalculateNormals();
     
     meshCollider.sharedMesh = mesh;
     
 }
 
 public void CreateMeshTarget(bool reset=false) {
     
     
     meshCollider = GetComponent<MeshCollider>();
     mesh = new Mesh();
     GetComponent<MeshFilter>().mesh = mesh;
     
     
     verts.Clear();
     tris.Clear();
     uv.Clear();
     
 }
 
 public void DrawBrick(int x, int y, int z, byte block) {
     
     Vector3 start = new Vector3(x, y, z);
     Vector3 offset1, offset2;
     
     if (IsTransparent(x, y - 1, z))
     {
         offset1 = Vector3.left;
         offset2 = Vector3.back;
         DrawFace(start + Vector3.right, offset1, offset2, block);
     }
     if (IsTransparent(x, y + 1, z))
     {
         offset1 = Vector3.right;
         offset2 = Vector3.back;
         DrawFace(start + Vector3.up, offset1, offset2, block);
     }
     
     if (IsTransparent(x - 1, y , z))
     {
         offset1 = Vector3.up;
         offset2 = Vector3.back;
         DrawFace(start , offset1, offset2, block);
     }
     
     if (IsTransparent(x + 1, y, z ))
     {
         offset1 = Vector3.down;
         offset2 = Vector3.back;
         DrawFace(start + Vector3.right + Vector3.up, offset1, offset2, block);
     }
     
     if (IsTransparent(x, y, z - 1))
     {
         offset1 = Vector3.left;
         offset2 = Vector3.up;
         DrawFace(start + Vector3.right + Vector3.back, offset1, offset2, block);
     }
     
     if (IsTransparent(x, y, z + 1))
     {
         offset1 = Vector3.right;
         offset2 = Vector3.up;
         DrawFace(start, offset1, offset2, block);
     }
     
     
 }
 
 
 public void DrawFace(Vector3 start, Vector3 offset1, Vector3 offset2, byte block)
 {
     int index = verts.Count;
     
     verts.Add (start);
     verts.Add (start + offset1);
     verts.Add (start + offset2);
     verts.Add (start + offset1 + offset2);
     
     Vector2 uvBase;
     switch (block)
     {
     default:
         uvBase = new Vector2(0.25f,0.25f);
         break;
     case 2:
         uvBase = new Vector2(0.75f,0.75f);
         break;
     case 3:
         uvBase = new Vector2(0.25f,0.75f);
         break;
     case 4:
         uvBase = new Vector2(0.75f,0.25f);
         break;
     }
     
     
     if ((offset1 == Vector3.right) && (offset2 == Vector3.back))
     {
         uv.Add (uvBase);
         uv.Add (uvBase + new Vector2(0.125f, 0));
         uv.Add (uvBase + new Vector2(0, 0.125f));
         uv.Add (uvBase + new Vector2(0.125f, 0.125f));
     }
     else
     {
         uv.Add (uvBase);
         uv.Add (uvBase + new Vector2(0.125f, 0));
         uv.Add (uvBase + new Vector2(0, 0.125f));
         uv.Add (uvBase + new Vector2(0.125f, 0.125f));
     }
     
     
     
     tris.Add(index + 0);
     tris.Add(index + 1);
     tris.Add(index + 2);
     tris.Add(index + 3);
     tris.Add(index + 2);
     tris.Add(index + 1);
 }
 
 public bool IsTransparent(int x, int y, int z)
 {
     if ((x< 0) || (y < 0) || (z < 0) || (x >= width) || (y >= height) || (z >= width)) return true; 
     return map[x, y, z] == 0;
 }
 
 public void Regenerate() {
     if (! initialized) return;
     
     CreateMeshTarget(true);
     
     mesh.triangles = tris.ToArray();
     
     for (int y = 0; y < height; y++)
     {
         
         for (int x = 0; x < width; x++)
         {
             for (int z = 0; z < width; z++)
             {
                 
                 byte block = map[x,y,z];
                 if (block == 0) continue;
                 
                 DrawBrick(x, y, z, block); 
             }
         }
     }
     
     
     CloseMeshTarget();
 }
 public void SetBrick(int x, int y, int z, byte block)
 {
     if (y == 0) return;
     x -= Mathf.RoundToInt(transform.position.x);
     y -= Mathf.RoundToInt(transform.position.y);
     z -= Mathf.RoundToInt(transform.position.z);
     
     if ((x < 0) || (y < 0) || (z < 0) || (x >= width) || (y >= height) || (z >= width)) return;
     
     if (map[x, y, z] != block) 
     {
         map[x, y, z] = block;
         Regenerate();
     }
 }
 
 
 public static List<LandBrush> GetBrushesFor(float x, float z) {
     List<LandBrush> brushes = new List<LandBrush>();
     
     TerrainType terrainType = GetTerrainFor(x,z);

     Terrain terrain = Camera.main.GetComponent<Terrain>();
     Random.seed = terrain.seed + Mathf.FloorToInt(x * 7 + z * 13);
     
     
     float numBrushes = 12;
     while (numBrushes > 0)
     {
         numBrushes--;
         brushes.Add (new LandBrush(x, z, terrain.chunkSize, terrainType));
     }
     
     return brushes;
 }

 public static TerrainType GetTerrainFor(float x, float z) {
     Terrain terrain = Camera.main.GetComponent<Terrain>();
     Random.seed = terrain.seed + Mathf.FloorToInt(x * 7 + z * 13);
     return (TerrainType)Mathf.FloorToInt(Random.value * 3);
 }

 public static float GetGroundHeight(TerrainType terrainType){
     switch (terrainType)
     {
     case TerrainType.Lowlands: 
         return 8;
     case TerrainType.Highlands:
         return 12;
     case TerrainType.Mountains:
         return  30;
     default:
         return 1;

     }
 }

 public static float CurvePoint(float percent, float val1, float val2, val3) {
     float p1 = (1 - percent) * val1 + percent * val2;
     float p2 = (1 - percent) * val2 + percent * val3;
     return (1 - percent) * p1 + percent * p2;
     } 
 }

Displays the error:

Assets/Scripts/Chunk.cs(98,19): error CS8025: Parsing error Assets/Scripts/Chunk.cs(92,47): error CS1519: Unexpected symbol ++' in class, struct, or interface member declaration Assets/Scripts/Chunk.cs(92,39): error CS1519: Unexpected symbol <=' in class, struct, or interface member declaration Assets/Scripts/Chunk.cs(90,39): error CS1519: Unexpected symbol ++' in class, struct, or interface member declaration Assets/Scripts/Chunk.cs(90,31): error CS1519: Unexpected symbol <=' in class, struct, or interface member declaration Assets/Scripts/Chunk.cs(90,11): error CS1519: Unexpected symbol `for' in class, struct, or interface member declaration

HELP please!

Comment
Add comment · Show 1
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 robertbu · Mar 02, 2014 at 01:24 PM 1
Share

This is not a simple syntax error fix. The Start() function is ter$$anonymous$$ated on line 60. That means all the code between that point and the start of the Update() function is outside of any function and just floating in the middle of the class.

0 Replies

· Add your reply
  • Sort: 

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

No appropriate version of 'UnityEngine.Object.Instantiate. Please Help :( 1 Answer

How can I convert this code to Unity Android? 1 Answer

CAN SOMEONE FINALLY HELP ME! 3 Answers

The code is giving me errors 1 Answer

Unassigned Reference Exception? 1 Answer


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