Tilemap代码相关

public class L23 : MonoBehaviour
{
    //瓦片地图信息,可以得到瓦片格子(场景中的Tilemap物体)
    public Tilemap map;
    //瓦片位置控制,坐标转换(场景中的Grid物体)
    public Grid grid;
    //瓦片资源基类,得到瓦片资源(本地的单个瓦片图片)
    public TileBase tileBase;
    // Start is called before the first frame update
    void Start()
    {
        //清空瓦片地图
        map.ClearAllTiles();

        //获取指定坐标格子
        TileBase tempBase=  map.GetTile(new Vector3Int(0, 0, 0));

        //设置瓦片
        map.SetTile(Vector3Int.zero, tileBase);
        
        //设置多张map.SetTiles()

        //删除瓦片
        map.SetTile(Vector3Int.zero,null);

        //替换一类瓦片(被替换的瓦片,新的瓦片)
        map.SwapTile(tempBase, tileBase);

        //世界坐标转格子坐标
        grid.WorldToCell(Vector3.zero);
        //可以通过屏幕坐标转世界坐标再转格子坐标进行一些特殊处理
    }
}
posted @ 2025-03-28 20:35  cannedmint  阅读(26)  评论(0)    收藏  举报