简体   繁体   English

如何检查具有统一图块图的不同图块?

[英]How to check for different tile with unity tilemaps?

Every example I've found only to do with the new tilemap system only looks for a tile using GetTile and then checks it against itself using "this". 我发现的每个仅与新的tilemap系统有关的示例都仅使用GetTile查找一个tile,然后使用“ this”对照自身进行检查。 EG. 例如。

private bool HasOtherTile(ITilemap tilemap, Vector3Int position)
{
    return tilemap.GetTile(position) == this;
}

I want to be able to check for a other specific tiles instead. 我希望能够检查其他特定的图块。 Such as a WallTile.asset tile with a my public class WallTile : TileBase script attached I've created. 例如带有我创建的public class WallTile : TileBase脚本的public class WallTile : TileBase贴。 I'm really stuck on how to do this. 我真的对如何做到这一点感到困惑。

I've tried using 我试过使用

gameObject.AddComponent(WaterTile)

TileBase tileTest = gameObject.AddComponent(WallTile);


private bool HasRoadTile(ITilemap tilemap, Vector3Int position)
{
    TileBase tileTest = gameObject.AddComponent(WaterTile);
    return tilemap.GetTile(position) == tileTest;
}

But this doesnt seem to work. 但这似乎不起作用。

I've also tried ScriptableObject.CreateInstance(WaterTile) which also doesn't work. 我也尝试了ScriptableObject.CreateInstance(WaterTile) ,它也无法正常工作。

@Sandro Figo The GetTile method doesn't seem to have an extension method for gameObject it seems. @Sandro Figo GetTile方法似乎没有gameObject的扩展方法。

It returns "T Tile of type T placed at the cell." 它返回“放置在单元格上的T类型的T Tile”。

To check for the tile type at a position: 要检查某个位置的瓷砖类型:

public bool IsTileOfType<T>(ITilemap tilemap, Vector3Int position) where T : TileBase
{
    TileBase targetTile = tilemap.GetTile(position);

    if (targetTile != null && targetTile is T)
    {
        return true;
    }

    return false;
}

Regarding gameobject of a tile: 关于图块的游戏对象:

Your tiles must inherit from Tile class not TileBase in order to manipulate its gameobject. 您的图块必须继承自Tile类而不是TileBase才能操作其游戏对象。

Try this: 尝试这个:

private bool HasWallTile(ITilemap tilemap, Vector3Int position)
{
    return tilemap.GetTile(position).gameObject.GetComponent<WallTile>() != null;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何统一检查两个瓷砖地图之间的碰撞? - How to check for collisions between two tilemaps in unity? Unity TileMaps:如何返回占据特定Vector3位置的图块的图层名称,标签或其他标识信息? - Unity TileMaps: How do I return the Layer name, Tag, or other identifying information of a tile that occupies a particular Vector3 location? Unity Tilemaps, Single Tile Collision detection for highlighting Tiles/Cells, 奇怪的行为 - Unity Tilemaps, Single Tile Collision detection for highlighting Tiles/Cells, strange behaviour 已解决:Unity Tilemap - 如何将多个 tilemap 合并到一个数组中 - SOLVED: Unity Tilemap - How to merge more tilemaps into one array Unity - 如何检查在 x,y,z 位置是否有特定 Tilemap 的 Tile - Unity - How to check if there is a Tile of an specific Tilemap in the position x,y,z Unity 2d 自顶向下 RPG 风格,如何通过图层顺序排序处理 tilemaps - Unity 2d top down RPG-style, How to handle tilemaps with layer order sorting 如何在 Unity 中输入瓦片时将 NavMeshAgents 排队(基于到瓦片的路径距离)? - How to queue NavMeshAgents on entering a tile in Unity (based on path distance to tile)? 如何在Unity TileSystem中停止平铺动画? - How to stop tile animation in Unity TileSystem? Tilemaps.Tilemap.SetTile() 据说不存在(Unity) - Tilemaps.Tilemap.SetTile() supposedly doesn't exist(Unity) 在 Unity 中制作瓷砖网格 - Making a tile grid in Unity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM