Not really sure about the plugin that you bought, but If you are using tilemaps, you could iterate over every tile in each tilemap in your grid(only once on level loading) and generate a random number of x and y to choose a valid tile position from and make the Ai move there using the A* algorithm.
Edit: May not be the best way to write this, but this is how I iterated over them in the past, you can add or change things in it for your future needs if you want.
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Tilemaps;
public class TileMapCollision : MonoBehaviour
{
[SerializeField] private GameObject gridObject;
private TileBase tile;
public List<Vector3> StoredStaticSolidTilePositions;
private void Awake()
{
TileSearch();
}
private void TileSearch()
{
List<Tilemap> tilemaps = gridObject.GetComponentsInChildren<Tilemap>().ToList();
foreach (Tilemap tilemap in tilemaps)
{
tilemap.CompressBounds();
BoundsInt TilemapBounds = tilemap.cellBounds;
for (int x = TilemapBounds.xMin; x < TilemapBounds.xMax; x++)
{
for (int y = TilemapBounds.yMin; y < TilemapBounds.yMax; y++)
{
Vector3Int localPos = new Vector3Int(x,y, (int)tilemap.transform.position.z);
Vector3 worldPos = tilemap.CellToWorld(localPos);
if (tilemap.HasTile(localPos))
{
if (tilemap.CompareTag("Solid"))
{
StoredStaticSolidTilePositions.Add(worldPos);
}
}
}
}
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…