[英]Generating an empty tilemap in unity
I want to create a TD game where the map is tilemap that generated in runtime.我想创建一个 TD 游戏,其中 map 是在运行时生成的 tilemap。 for the moment I am trying to create the tilemap with empty tile just for the start and after that, I will use the A-star algorithm to make the path.
目前我正在尝试创建带有空瓷砖的瓷砖地图,然后,我将使用 A-star 算法来制作路径。 currently, I have this function written below.
目前,我有这个 function 写在下面。 Everything is working and I can see the grid and tilemap in the editor when the gamestart but the tiles are not there...
一切正常,当游戏开始时我可以在编辑器中看到网格和瓷砖地图,但瓷砖不存在......
void initTilemap(){
GameObject grid = new GameObject("Grid");
GameObject tilemap = new GameObject("Tilemap");
grid.AddComponent<Grid>();
tilemap.AddComponent<Tilemap>();
tilemap.transform.SetParent(grid.transform);
collidableMap = tilemap.GetComponent<Tilemap>();
collidableMap.ClearAllTiles();
Tile tile = (Tile) Resources.Load("Tile/grass");
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
Vector3Int p = new Vector3Int(x,y,0);
// GameObject tile = new GameObject("TileBase");
collidableMap.SetTile(p, tile);
}
}
}
You may need to call RefreshAllTiles() on the TileMap after you make modifications in code.修改代码后,您可能需要在 TileMap 上调用RefreshAllTiles() 。
solved it by adding TilemapRenderer Component通过添加 TilemapRenderer 组件解决了它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.