0
게임에서와 같이 맵에서 맵을 생성하고 싶습니다. Unity와 C를 사용하여 Terraria와 Starbound를 사용하고 있습니다. 지금까지 한 작업이 효과가 없었으며 이유가 없습니다 ... 어떤 도움/아이디어/제안입니까?Terraria와 같은 무작위 타일 기반지도 생성이 통일 되었습니까?
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 <= maxHeightAllowed; y++) {
int heightDiff = y - nullDispersion;
float dispersionModifier = Mathf.Sin((heightDiff/dispersionZone) * 90);
float random = Random.Range(0, 1);
if(random > 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);
}
}
}
}
(heightDiff/dispersionZone)
* 무엇이 작동하지 않는지 말할 필요가 있습니다. 지금까지 코드 덤프를 보았습니다. – BradleyDotNET
아 .. 지금은 단 하나의 단색 블록을 생성합니다 ... Terraria와 같은 무작위지도를 만들어야합니다. :) –