[英]Unity - Spawning enemies on land
I am new at Unity and I am stuck on one thing.我是 Unity 的新手,我被困在一件事上。 I would like to ensure that the enemies spawn on the grass and not in the water and not on the colliders.我想确保敌人产卵在草地上,而不是在水中,而不是在对撞机上。 I created the map using the Tiled program.我使用 Tiled 程序创建了地图。 Is there an effective solution?有没有有效的解决办法? Thank you.谢谢你。
If you are writing a strategy type game, you will need to store data about the map tiles in a 2D array like Map[x,y] so you can calculate things like movement, combat, resource gathering,victory points.如果您正在编写策略类型的游戏,则需要将有关地图图块的数据存储在像 Map[x,y] 这样的 2D 数组中,以便您可以计算移动、战斗、资源收集、胜利点等内容。
I have a TileType structure containing info on each tile based on your game rule requirements eg:我有一个 TileType 结构,其中包含基于您的游戏规则要求的每个图块的信息,例如:
struct TileType
{
public int TerrainType; // Terain type 1= grass 2= water 3 = city etc
public int rot; // Rotation of sprite to create variation (1-4,1=90 deg,2=180 deg etc
public string Name; // Description of tile type eg "Sports Store"
public string SpriteName; // string of sprite to use to display tile
public bool SeeThrough; // True if Tile allows LOS through it
}
I would set up the map as a 2D array of these tileType as follows:我会将地图设置为这些 tileType 的二维数组,如下所示:
private TileType[,] Map = new TileType[MapMaxX, MapMaxY];
You can then allow your game logic (ie where to spawn units) to check the proposed tile is legal as follows然后,您可以让您的游戏逻辑(即在哪里生成单位)检查提议的图块是否合法,如下所示
if ((Map[x, y].TerrainType=1)) // Grass tile
{ return true; }
else
{
return false; // Non grass tile
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.