I am trying to generate a simple random map with different biomes, parts, Every time I generate a world with this it just fills the grid with the same block.
Heres the code:
using UnityEngine;
using System.Collections;
public class TerrainGen : MonoBehaviour {
public GameObject[] floorWater;
public GameObject[] floorSand;
public GameObject[] floorStone;
public GameObject[] floorGrass;
public GameObject[] floorDirt;
public int mapWidth;
public int mapHeight;
private Transform Board;
private float seed;
void generateTerrain()
{
Board = new GameObject ("Board").transform;
for (int x = 0; x < mapWidth; x++)
{
for (int y = 0; y < mapHeight; y++)
{
seed = Random.Range (0, 0.9f);
float biome = Mathf.PerlinNoise (x, y)+seed;
GameObject toInstantiate;
GameObject instantiate;
if (biome >= 0 || biome < 0.2)
{
toInstantiate = floorWater [Random.Range (0, floorWater.Length)];
instantiate = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
instantiate.transform.SetParent (Board);
}
if (biome >= 0.2 || biome < 0.4)
{
toInstantiate = floorSand [Random.Range (0, floorSand.Length)];
instantiate = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
instantiate.transform.SetParent (Board);
}
if (biome >= 0.4 || biome < 0.6)
{
toInstantiate = floorDirt [Random.Range (0, floorDirt.Length)];
instantiate = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
instantiate.transform.SetParent (Board);
}
if (biome >= 0.6 || biome < 0.8)
{
toInstantiate = floorGrass [Random.Range (0, floorGrass.Length)];
instantiate = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
instantiate.transform.SetParent (Board);
}
if (biome >= 0.8)
{
toInstantiate = floorStone [Random.Range (0, floorStone.Length)];
instantiate = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
instantiate.transform.SetParent (Board);
}
}
}
}
void Start ()
{
generateTerrain ();
}
void Update ()
{
}
}
Any help would be appreciated. Thanks.