How to make AI follow multiple targets

Hello. I’m making a game about wars and stuff, but i couldn’t get the AI to follow multiple enemies. I searched all over the internet, but i couldn’t find a solution to my problem. Is someone able to help?

Can you explain a bit further? Follow multiple enemies at once? Follow multiple enemies one after the other? Etc.

Also, what have you tried? Can you share some code (use code tags from the text ribbon pleeeease)?

The idea is, that i’ll give one side an “Enemy” tag, and another side “Allies” tag. The allies will follow the closest object from the enemies, and the enemies will follow the closest object from the allies. The code that i tried was for a newer version of unity (I’m using 2018, since i don’t have space to update it to a newer version.), so i deleted it.

Also, the objects are 3D, but in a 2D space. So cubes, triangles etc…

Im a bit confused still. “The allies will follow the closest object from the enemies”, what object are they following? Projectiles? The enemies themselves?

Well, regardless, try out a tutorial like this:

Once you get the basic logic down, you can adapt to whatever you are trying to do.

yes, i already watched this video. But half the code in it doesn’t work. It’s probably because im in an older version of unity. I’m sorry i can’t explain it too well, but i’ll try again. There are 2 teams. Enemies and Allies. The enemies spawn on the X- side of the map, and the allies spawn on the X+ side of the map. Allies will have “Ally” tag and Enemies will have “Enemy” tag. Enemies will follow the closest object, that has the “Ally” tag and allies will follow the closest object that has the “Enemy” tag. It will path find to the closest one, and go to it. That’s the whole idea.