Question by
jaozingames · Oct 13, 2020 at 02:44 PM ·
c#errorcodepage
Unity don't recognize the elements, just the first i put, what can i do?,Unity don't recognize element 1, what can i do?
public class WorldGenerator : MonoBehaviour { public GameObject player;
public int sizeX;
public int sizeZ;
public int groundHeight;
public float terDetail;
public float terHeight;
int seed;
public GameObject[] blocks;
// Start is called before the first frame update
void Start()
{
seed = Random.Range(100000, 999999);
GenerateTerrain();
}
// Update is called once per frame
void Update()
{
}
void GenerateTerrain()
{
for (int x = 0; x < sizeX; x++)
{
for (int z = 0; z < sizeZ; z++)
{
int maxY = (int)(Mathf.PerlinNoise((x / 2 + seed) / terDetail, (z / 2 + seed) / terDetail) * terHeight);
maxY += groundHeight;
GameObject Grass = Instantiate(blocks[0], new Vector3(x, maxY, z), Quaternion.identity)as GameObject;
Grass.transform.SetParent(GameObject.FindGameObjectWithTag("Environment").transform);
for (int y = 0; y < maxY; y++)
{
GameObject stone = Instantiate(blocks[1], new Vector3(x, y, z), Quaternion.identity) as GameObject;
stone.transform.SetParent(GameObject.FindGameObjectWithTag("Environment").transform);
}
if (x == (int)(sizeX / 2) && z == (int)(sizeZ / 2))
{
Instantiate(player, new Vector3(x, maxY + 3, z), Quaternion.identity);
}
}
}
}
} ,public class WorldGenerator : MonoBehaviour { public GameObject player;
public int sizeX;
public int sizeZ;
public int groundHeight;
public float terDetail;
public float terHeight;
int seed;
public GameObject[] blocks;
// Start is called before the first frame update
void Start()
{
seed = Random.Range(100000, 999999);
GenerateTerrain();
}
// Update is called once per frame
void Update()
{
}
void GenerateTerrain()
{
for (int x = 0; x < sizeX; x++)
{
for (int z = 0; z < sizeZ; z++)
{
int maxY = (int)(Mathf.PerlinNoise((x / 2 + seed) / terDetail, (z / 2 + seed) / terDetail) * terHeight);
maxY += groundHeight;
GameObject Grass = Instantiate(blocks[0], new Vector3(x, maxY, z), Quaternion.identity)as GameObject;
Grass.transform.SetParent(GameObject.FindGameObjectWithTag("Environment").transform);
for (int y = 0; y < maxY; y++)
{
GameObject stone = Instantiate(blocks[1], new Vector3(x, y, z), Quaternion.identity) as GameObject;
stone.transform.SetParent(GameObject.FindGameObjectWithTag("Environment").transform);
}
if (x == (int)(sizeX / 2) && z == (int)(sizeZ / 2))
{
Instantiate(player, new Vector3(x, maxY + 3, z), Quaternion.identity);
}
}
}
}
}
Comment