- Home /
Newline in constant?
It says in the console that there is a newline in constant on every line. What does it mean and how do i fix it? Do you need all of my code to solve the problem? Please help!
void GenerationMesh(){
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 the block is solid
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));
}
}
}
}
}
Can you please provide the exact Error your receiving, dont paraphrase it as its very important exactly what it is.
Assets/$$anonymous$$y Assets/Scripts/RandomGeneration/World.cs(48,0): error CS1010: Newline in constant
Its on every line from 48 to 94
Full Script:
using UnityEngine; using System.Collections;
public class World : $$anonymous$$onoBehaviour {
public byte[,,] data;
public int worldX=16;
public int worldY=16;
public int worldZ=16;
public GameObject chunk;
public GameObject[,,] chunks;
public int chunkSize = 16;
void Start () {
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,2,0) +1; //Added +1 to make sure $$anonymous$$imum grass height is 1
for (int y=0; y<worldY; y++){
if(y<=stone){
data[x,y,z]=1;
} else if(y<=dirt+stone){ //Changed this line thanks to a comment
data[x,y,z]=2;
}
}
}
}
chunks=new GameObject[$$anonymous$$athf.FloorToInt(worldX/chunkSize),
$$anonymous$$athf.FloorToInt(worldY/chunkSize),
$$anonymous$$athf.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;
}
}
}
data = new byte[worldX,worldY,worldZ];
for (int x=0; x<worldX; x++){
for (int y=0; y<worldY; y++){
for (int z=0; z<worldZ; z++){
if(y<=8){
data[x,y,z]=1;
}
}
}
}
}
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];
}
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=$$anonymous$$athf.Pow( rValue, power);
}
return (int) rValue;
}
}
Answer by mattyman174 · Feb 21, 2014 at 12:38 AM
Chunk newChunkScript= chunks[x,y,z].GetComponent(\"Chunk\") as Chunk;
Where you define the Component type is incorrect. Remove the \ from the String as such.
Chunk newChunkScript= chunks[x,y,z].GetComponent("Chunk") as Chunk;
Your answer
Follow this Question
Related Questions
C# Newline in constant. 1 Answer
Remove "new lines" from string variable? C# 2 Answers
Change Prefab Source/Change material on ALL prefabs in the scene 0 Answers
Change to constantly move forward 1 Answer