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
1
Question by iamthecoolguy11 · Jan 19, 2014 at 02:55 PM · c#errornewline

how do i fix (error CS1010 Newline in constant)

I made these 2 scripts and when I finished them they both got the same errors and I don't know what they are from. alt text

and here is the scripts.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 public class Chunk : MonoBehaviour {
     
     public GameObject worldGO;
     private World world;
     
     private List<Vector3> newVertices = new List<Vector3>();
     private List<int> newTriangles = new List<int>();
     private List<Vector2> newUV = new List<Vector2>();
     
     private float tUnit = 0.25f;
     private Vector2 tStone = new Vector2 (1, 0);
     private Vector2 tGrass = new Vector2 (0, 1);
     private Vector2 tGrassTop = new Vector2 (1, 1);
     
     private Mesh mesh;
     private MeshCollider col;
     
     private int faceCount;
     
     public int chunkSize=16;
     
     public int chunkX;
     public int chunkY;
     public int chunkZ;
     
     // Use this for initialization
     void Start () { 
         
         world=worldGO.GetComponent(\"World\") as World;
    
   mesh = GetComponent<MeshFilter> ().mesh;
   col = GetComponent<MeshCollider> ();
    
   GenerateMesh();
    
    
  }
   
  // Update is called once per frame
  void Update () {
    
  }
   
  void GenerateMesh(){
    
   for (int x=0; x<chunkSize; x++){
    for (int y=0; y<chunkSize; y++){
     for (int z=0; z<chunkSize; z++){
      //This code will run for every block in the chunk
       
      if(Block(x,y,z)!=0){
       if(Block(x,y+1,z)==0){
        //Block above is air
        CubeTop(x,y,z,Block(x,y,z));
       }
        
       if(Block(x,y-1,z)==0){
        //Block below is air
        CubeBot(x,y,z,Block(x,y,z));
         
       }
        
       if(Block(x+1,y,z)==0){
        //Block east is air
        CubeEast(x,y,z,Block(x,y,z));
         
       }
        
       if(Block(x-1,y,z)==0){
        //Block west is air
        CubeWest(x,y,z,Block(x,y,z));
         
       }
        
       if(Block(x,y,z+1)==0){
        //Block north is air
        CubeNorth(x,y,z,Block(x,y,z));
         
       }
        
       if(Block(x,y,z-1)==0){
        //Block south is air
        CubeSouth(x,y,z,Block(x,y,z));
         
       }
        
      }
       
     }
    }
   }
    
   UpdateMesh ();
  }
   
  byte Block(int x, int y, int z){
   return world.Block(x+chunkX,y+chunkY,z+chunkZ);
  }
   
  void CubeTop (int x, int y, int z, byte block) {
    
   newVertices.Add(new Vector3 (x,  y,  z + 1));
   newVertices.Add(new Vector3 (x + 1, y,  z + 1));
   newVertices.Add(new Vector3 (x + 1, y,  z ));
   newVertices.Add(new Vector3 (x,  y,  z ));
    
   Vector2 texturePos=new Vector2(0,0);
    
   if(Block(x,y,z)==1){
    texturePos=tStone;
   } else if(Block(x,y,z)==2){
    texturePos=tGrassTop;
   }
    
   Cube (texturePos);
    
  }
   
  void CubeNorth (int x, int y, int z, byte block) {
    
   newVertices.Add(new Vector3 (x + 1, y-1, z + 1));
   newVertices.Add(new Vector3 (x + 1, y, z + 1));
   newVertices.Add(new Vector3 (x, y, z + 1));
   newVertices.Add(new Vector3 (x, y-1, z + 1));
    
   Vector2 texturePos=new Vector2(0,0);
    
   if(Block(x,y,z)==1){
    texturePos=tStone;
   } else if(Block(x,y,z)==2){
    texturePos=tGrass;
   }
    
   Cube (texturePos);
    
  }
   
  void CubeEast (int x, int y, int z, byte block) {
    
   newVertices.Add(new Vector3 (x + 1, y - 1, z));
   newVertices.Add(new Vector3 (x + 1, y, z));
   newVertices.Add(new Vector3 (x + 1, y, z + 1));
   newVertices.Add(new Vector3 (x + 1, y - 1, z + 1));
    
   Vector2 texturePos=new Vector2(0,0);
    
   if(Block(x,y,z)==1){
    texturePos=tStone;
   } else if(Block(x,y,z)==2){
    texturePos=tGrass;
   }
    
   Cube (texturePos);
    
  }
   
  void CubeSouth (int x, int y, int z, byte block) {
    
   newVertices.Add(new Vector3 (x, y - 1, z));
   newVertices.Add(new Vector3 (x, y, z));
   newVertices.Add(new Vector3 (x + 1, y, z));
   newVertices.Add(new Vector3 (x + 1, y - 1, z));
    
   Vector2 texturePos=new Vector2(0,0);
    
   if(Block(x,y,z)==1){
    texturePos=tStone;
   } else if(Block(x,y,z)==2){
    texturePos=tGrass;
   }
    
   Cube (texturePos);
    
  }
   
  void CubeWest (int x, int y, int z, byte block) {
    
   newVertices.Add(new Vector3 (x, y- 1, z + 1));
   newVertices.Add(new Vector3 (x, y, z + 1));
   newVertices.Add(new Vector3 (x, y, z));
   newVertices.Add(new Vector3 (x, y - 1, z));
    
   Vector2 texturePos=new Vector2(0,0);
    
   if(Block(x,y,z)==1){
    texturePos=tStone;
   } else if(Block(x,y,z)==2){
    texturePos=tGrass;
   }
    
   Cube (texturePos);
    
  }
   
  void CubeBot (int x, int y, int z, byte block) {
    
   newVertices.Add(new Vector3 (x,  y-1,  z ));
   newVertices.Add(new Vector3 (x + 1, y-1,  z ));
   newVertices.Add(new Vector3 (x + 1, y-1,  z + 1));
   newVertices.Add(new Vector3 (x,  y-1,  z + 1));
    
   Vector2 texturePos=new Vector2(0,0);
    
   if(Block(x,y,z)==1){
    texturePos=tStone;
   } else if(Block(x,y,z)==2){
    texturePos=tGrass;
   }
    
   Cube (texturePos);
    
  }
   
  void Cube (Vector2 texturePos) {
    
   newTriangles.Add(faceCount * 4  ); //1
   newTriangles.Add(faceCount * 4 + 1 ); //2
   newTriangles.Add(faceCount * 4 + 2 ); //3
   newTriangles.Add(faceCount * 4  ); //1
   newTriangles.Add(faceCount * 4 + 2 ); //3
   newTriangles.Add(faceCount * 4 + 3 ); //4
    
   newUV.Add(new Vector2 (tUnit * texturePos.x + tUnit, tUnit * texturePos.y));
   newUV.Add(new Vector2 (tUnit * texturePos.x + tUnit, tUnit * texturePos.y + tUnit));
   newUV.Add(new Vector2 (tUnit * texturePos.x, tUnit * texturePos.y + tUnit));
   newUV.Add(new Vector2 (tUnit * texturePos.x, tUnit * texturePos.y));
    
   faceCount++; // Add this line
  }
   
  void UpdateMesh ()
  {
    
   mesh.Clear ();
   mesh.vertices = newVertices.ToArray();
   mesh.uv = newUV.ToArray();
   mesh.triangles = newTriangles.ToArray();
   mesh.Optimize ();
   mesh.RecalculateNormals ();
    
   col.sharedMesh=null;
   col.sharedMesh=mesh;
    
   newVertices.Clear();
   newUV.Clear();
   newTriangles.Clear();
   faceCount=0;
    
  }
 }

and script 2 using UnityEngine; using System.Collections;

 public class World : MonoBehaviour {
     
     public GameObject chunk;
     public GameObject[,,] chunks;
     public int chunkSize=16;
     
     public byte[,,] data;
     public int worldX=16;
     public int worldY=16;
     public int worldZ=16;
     
     // Use this for initialization
     void Start () {
         
         data = new byte[worldX,worldY,worldZ];
         
         for (int x=0; x<worldX; x++){
             for (int z=0; z<worldZ; z++){
                 int stone=PerlinNoise(x,0,z,10,3,1.2f);
                 stone+= PerlinNoise(x,300,z,20,4,0)+10;
                 int dirt=PerlinNoise(x,100,z,50,3,0)+1;
                 
                 for (int y=0; y<worldY; y++){
                     if(y<=stone){
                         data[x,y,z]=1;
                     } else if(y<=dirt+stone){
                         data[x,y,z]=2;
                     }
                     
                 }
             }
         }
         
         
         chunks=new GameObject[Mathf.FloorToInt(worldX/chunkSize),Mathf.FloorToInt(worldY/chunkSize),Mathf.FloorToInt(worldZ/chunkSize)];
         
         for (int x=0; x<chunks.GetLength(0); x++){
             for (int y=0; y<chunks.GetLength(1); y++){
                 for (int z=0; z<chunks.GetLength(2); z++){
                     
                     chunks[x,y,z]= Instantiate(chunk,new Vector3(x*chunkSize,y*chunkSize,z*chunkSize),new Quaternion(0,0,0,0)) as GameObject;
                     Chunk newChunkScript= chunks[x,y,z].GetComponent(\"Chunk\") as Chunk;
      newChunkScript.worldGO=gameObject;
      newChunkScript.chunkSize=chunkSize;
      newChunkScript.chunkX=x*chunkSize;
      newChunkScript.chunkY=y*chunkSize;
      newChunkScript.chunkZ=z*chunkSize;
       
     }
    }
   }
    
  }
   
  int PerlinNoise(int x,int y, int z, float scale, float height, float power){
   float rValue;
   rValue=Noise.GetNoise (((double)x) / scale, ((double)y)/ scale, ((double)z) / scale);
   rValue*=height;
    
   if(power!=0){
    rValue=Mathf.Pow( rValue, power);
   }
    
   return (int) rValue;
  }
   
   
  // Update is called once per frame
  void Update () {
   
  }
   
  public byte Block(int x, int y, int z){
    
   if( x>=worldX || x<0 || y>=worldY || y<0 || z>=worldZ || z<0){
    return (byte) 1;
   }
    
   return data[x,y,z];
  }
 }
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
1
Best Answer

Answer by KellyThomas · Jan 19, 2014 at 03:05 PM

   world=worldGO.GetComponent(\"World\") as World;

Should be:

 world=worldGO.GetComponent("World") as World;

You don't want to escape the quotes around your literal string.

Look for something similar on the line reported in you other error as well.

Comment
Add comment · Show 1 · 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 iamthecoolguy11 · Jan 19, 2014 at 05:05 PM 0
Share

thanks man :)

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

19 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

Related Questions

Multiple Cars not working 1 Answer

C# Newline in constant. 1 Answer

Distribute terrain in zones 3 Answers

Passing string to facebook api for wall post, ignores newline 0 Answers

How do I solve this error? 2 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