Я хотел бы сгенерировать карту с плиток, как в играх Terraria и Starbound, используя Unity и C#
Что я сделал до сих пор, не работает, и я понятия не имею, почему ... любая помощь /идеи /предложения? < /p>
using UnityEngine;
using System.Collections;
public class MapGeneration : MonoBehaviour {
public int mapWidth, mapHeight, spreadDegree;
GameObject[,] blocks;
public GameObject baseBlock;
public int maxHeightAllowed;
public int nullDispersion;
int dispersionZone;
void Start() {
GenerateMap();
}
void GenerateMap() {
dispersionZone = maxHeightAllowed - nullDispersion;
blocks = new GameObject[mapWidth, mapHeight];
for(int x = 0; x < blocks.GetLength(0); x++) {
for(int y = nullDispersion; y dispersionModifier) {
blocks[x,y] = (GameObject)Instantiate(baseBlock, new Vector2(x, y), Quaternion.identity);
} else if (y < blocks.GetLength(1) && blocks[x,y+1] != null) {
blocks[x,y] = (GameObject)Instantiate(baseBlock, new Vector2(x, y), Quaternion.identity);
}
}
for(int y = 0; y < nullDispersion; y++) {
blocks[x,y] = (GameObject)Instantiate(baseBlock, new Vector2(x, y), Quaternion.identity);
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/266 ... a-in-unity