- Home /
Terraria like map generating
Im trying to get a map generator to work, but so far no luck. Does anyone know why my code is not working?
public void GenerateChunk1() { GameObject grassy = (GameObject)Resources.Load("grass"); GameObject stony = (GameObject)Resources.Load("stone"); int rawr = 1; System.Random rand = new System.Random(); Vector3 pos1 = new Vector3(0, 0, 0); Height = 5; Length = 4; for (int z = 0; z < 10; z += 4) { Length = 4 + z; //Build Chunk 1 #region Chunk1 for (int H = 15 - rand.Next(4); H < Height; H++) { for (int W = 0 + z; W < Length; W++) {
pos1 = new Vector3(W * 18 + 15, H * 18 + 15, 0);
// Rectangle rect = new Rectangle(W * 18, H * 18, 18, 18);
if (rawr > Length)
{
Instantiate(grassy, pos1, Quaternion.identity);
}
else
{
// int y = (Convert.ToInt16(pos1.Y) + Convert.ToInt16(rand.Next(3)));
// int x = (Convert.ToInt16(pos1.X));
// Vector2 pos3 = new Vector2(x, y);
Instantiate(grassy, pos1, Quaternion.identity);
rawr++;
}
}
#endregion
}
}
}
Format your code properly.
What is it supposed to be doing?
What is it doing ins$$anonymous$$d?
What fixes have you tried so far?
Trying to get a map generator, terraria esque type generator.
Answer by Pandamonium99 · Sep 10, 2012 at 03:10 AM
Trying to get a map generator, terraria esque type generator.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080833im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Block based map generator 5 Answers
Get quads from mesh? [SOLVED] 0 Answers
How do I create a random map out of existing patterns? 1 Answer
Percentage based chance in C#? 2 Answers
Simple 2D procedural galaxy map 2 Answers