Not sure if I described the problem correctly in the title, but I’m making a turn-based game and have the enemy movement AI finished. The problem I’ve got stuck on is making each enemy move separately:
Enemy 1: move and attack
Then
Enemy 2: move and attack
and so forth.
I suppose I could do separate scripts but that would just be a mess in the long run. Do any of you know a more straightforward way of doing it using the same script?
I’m kind of new to game dev and this forum so if this is posted in the wrong forum, please tell me where I should post it instead:)
You can use an IEnumerator:
- You can create a IEnumerator and call it on each Action.
A cleaner Yield procedere:
- You can create a Custom Yield where you will process all the necessary logic and call it in an IEnumerator
I am using this procedere in our RPG and it works perfect.
get your list of enemies
public List enemiesList = new List();
Get all your enemies
Use a sorting function on your list, lets call it initiative for now.
Now your list is sorted from say low to high
Do a for loop over the enemiesList and check if the current enemy has finished its turn and isn’t busy executing its turn.
When you find it break out of the loop and set it to busy. When its done set finishedTurn to true.
That’s the basic unoptimized logic that’ll get you going in an update loop.