【问题标题】:How do I render an Isometric Tilemap in Unity via a script?如何通过脚本在 Unity 中渲染 Isometric Tilemap?
【发布时间】:2019-02-19 04:42:24
【问题描述】:

我是 Unity 的新手,所以请和我一起坚持下去。

我正在尝试为我的游戏地形构建一个等距平铺地图对象。平铺图像存储在二进制文件中。我已经阅读了 Unity 关于 Isometric Tilemaps 的文档,但我还不清楚如何通过脚本插入 tilemap 图像。

希望这里有人可以概述如何解决此问题或向我指出一些有用的文档。

如果有帮助,这里有一些关于我正在解析的二进制文件的简单文档:https://uo.stratics.com/heptazane/fileformats.shtml#3.8

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    如果你想在 (x,y) 坐标上设置瓦片,你可以使用 Tilemap 方法 SetTile(或更改 GetTile 方法的返回瓦片上的纹理),例如:

    //fields:
    public Tilemap Map;
    public TileBase[] TileTypes = { water, ground, mountain.....} //fill in the inspector (Texture2D/Sprite/Tile/Image/anything you want)
    
    //array = world from your binary file (I use int but you can use anything you want)
    public void GenerateTileMap (int[,] world)
    {
        for (int x = 0; x < world.GetLength(0); x++)
            for (int y = 0; y < world.GetLength(1); y++)
                Map.SetTile(new Vector3Int(x, y, 0), TileTypes[world[x, y]]);
    }
    

    在脚本 api 参考中阅读更多内容(查看公共方法):https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.html

    【讨论】:

      猜你喜欢
      • 2019-07-08
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 2017-12-23
      • 2022-01-17
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      相关资源
      最近更新 更多