How can I setup a AI Bot to Pathfind around my small map?
So, I have a small map for a mobile game made but I'm having a bit of trouble coming up with the concept of pathfinding around it. I have a player walk into my Store (the map) and create targets for different areas of the store. I want to create a line of code that will take into consideration the Players' current position, and the Target position and move to that spot. However, I have made specific other Transform game objects around the map for the Player to navigate to move around obstacles that might be in the way.
All of the BuyableObjects are the colorful places on the map as shown, each one has its own special Child called Buy Spot that has a transform placed right in front of the object so that the player can navigate to that if the object is the Players target.
The Walkways are empty game objects with Transforms attached to them. They are the in-between objects for the player to navigate to so that I can make sure they avoid walking directly through other objects to get to their target.
My code for going to the target is so far, this:
public IEnumerator GoToTarget()
{
Transform[] BuySpots;
BuySpots = new Transform[StoreObjects];
for(int i = 0; i < StoreObjects; i++)
{
Transform LocalSpot = BuyableObjects.transform.GetChild(i).Find("BuySpot");
BuySpots[i] = LocalSpot;
}
GameObject Target = Objects[Counter];
Counter = Counter + 1;
//Create Pathway
List<Transform> Pathway = new List<Transform>();
int PathwayTargets = 0;
if(gameObject.transform.position != Target.transform.position)
{
PathwayTargets = PathwayTargets + 1;
yield return null;
}
Everything before the Create Pathway comment is just setting up the variables to access the Transforms. So, depending on where the player is and what their target is decided how many places they will have to pathfind to on the map and where those places on the map will be.
I'm just not sure how to create code that could work like that, without making hundreds of if statements that would direct the player.
Does anyone know of a concept I could use? Or maybe another easier way of doing things that don't involve this level of Transform and complexity?