hello guys, tou have a problem that when the world is generated it does not generate all and this error “the thing you want to instantiate is null” Anyone know where should be the error?
using UnityEngine;
using System.Collections;
public class WorldGenerate : MonoBehaviour {
public int BlockSize = 1;
public int WorldWidth = 100;
public int WorldHeight = 20;
public int topOfTheWorld = 20;
public int yPos = 20;
public int slope = 0;
public int xPos = 0;
public int contBlocksInt = 0;
private GameObject [][] scene;
private string [] biomes;
public int TimeUntilNextBiome;
public string biome;
private string [] caves;
public int TimeUntilNextCave;
public string cave;
public GameObject World;
public Vector3 PositionBlock;
public GameObject air;
public GameObject stone;
public GameObject dirt;
public GameObject grass;
public GameObject coal;
public GameObject wood;
public GameObject leaves;
public GameObject sand;
public GameObject bedrock;
void Start () {
scene = new GameObject[100000][];
biomes = new string[10];
yPos = topOfTheWorld;
this.generate();
this.render();
}
void Update () {
}
public void generate(){
bool finished = false;
biomes[0] = "forest";
biomes[1] = "desert";
biome = biomes[Random.Range(0,2)];
caves[0] = "small";
caves[1] = "medium";
caves[2] = "large";
cave = biomes[Random.Range(0,3)];
TimeUntilNextBiome = Random.Range(0, 10) + 30;
TimeUntilNextCave = Random.Range(0, 30) + 30;
while(!finished){
if(scene[xPos] == null){
scene[xPos] = new GameObject[100000];
}
if(yPos == topOfTheWorld){
TimeUntilNextBiome--;
TimeUntilNextCave--;
if(TimeUntilNextBiome <= 0){
biome = biomes[Random.Range(0,2)];
TimeUntilNextBiome = Random.Range(0, 10) + 30;
}
if(TimeUntilNextCave <= 0){
cave = caves[Random.Range(0,3)];
TimeUntilNextCave = Random.Range(0, 30) + 30;
}
if(biome == "forest"){
scene[xPos][yPos] = grass;
if(Random.Range(0, 6) == 1){
scene[xPos][yPos + 1] = wood;
scene[xPos][yPos + 2] = wood;
scene[xPos][yPos + 3] = wood;
if(scene[xPos + 1] == null){
scene[xPos + 1] = new GameObject[10000];
}
scene[xPos - 1][yPos + 3] = leaves;
scene[xPos + 1][yPos + 3] = leaves;
scene[xPos][yPos + 4] = leaves;
}
}else if(biome == "desert"){
scene[xPos][yPos] = sand;
}
}else if(yPos >= topOfTheWorld - 3 && Random.Range(0, 3) != 1){
if(biome == "forest"){
scene[xPos][yPos] = dirt;
}else if(biome == "desert"){
scene[xPos][yPos] = sand;
}
}else if(yPos >= topOfTheWorld - 6 && Random.Range(0, 2) != 1){
if(biome == "forest"){
scene[xPos][yPos] = dirt;
}else if(biome == "desert"){
scene[xPos][yPos] = sand;
}
}else{
if(Random.Range(1, 100) == 1){
scene[xPos][yPos] = coal;
}else{
scene[xPos][yPos] = stone;
}
}
yPos--;
if(yPos < 0){
slope = Random.Range(0, 5) - 2;
if(topOfTheWorld < 10){
slope = 1;
}
if(topOfTheWorld > 30){
slope = -1;
}
topOfTheWorld += slope;
yPos = topOfTheWorld;
xPos++;
}
if(xPos > WorldWidth){
for(var i = 0; i <= WorldWidth; i++){
scene*[1] = bedrock;*
-
}*
-
for(var i = 0; i <= 50; i++){*
_ scene[1] = bedrock;_
* }*
* for(var i = 0; i <= 50; i++){*
_ scene[WorldWidth] = bedrock;_
* }*
* finished = true;*
* }*
* }*
* }*
* public void render(){*
* for(var x = 1; x <= WorldWidth; x++){*
* for(var y = 1; y <= WorldHeight; y++){*
* GameObject World = (GameObject)Instantiate(scene[x][y]) as GameObject;*
_ World.transform.position = new Vector3(x * BlockSize - BlockSize / 2, y * BlockSize + BlockSize / 2, 0);
* World.name = “bX” + World.transform.position.x+“bY” + World.transform.position.y;*_
* }*
* }*
* }*
}