In a top down, 2d, turn based roguelike in Unity3d 5 I am having an issue with game pacing. I am using a very simple state machine to control execution but I want enemies that all move in the same turn to do so with a pause between each one if they are in the players line of sight so that animations and sound have time to occur without overlapping (Especially sounds). The only issue I am having is getting the actual pause to occur without affecting animations or camera movement (The camera may be sliding to follow a player movement and it was stopping). I only need about a 100ms pause before moving to the next enemy.
The enemies are taking their actions in a foreach loop in an EnemyManager script
private void takeAllEnemyActions()
{
// Cycle through all enemies and have them perform their actions
if (Enemies != null && Enemies.Length > 0)
{
foreach (GameObject enemy in Enemies)
if (enemy.GetComponent<Enemy>().NextMoveTick <= GameManager.Instance.CurrentTick)
enemy.GetComponent<Enemy>().TakeEnemyActions();
}
GameManager.States.NextPlayState();
}
I tried creating a routine to invoke each enemy to act but the issue there was that execution of other enemies continued.
I tried using a coroutine but again the issue was the game would move on into the next state.
I even tried a while-do loop using Time.RealTimeSinceStartup just to see what it would do (I know, a very VERY bad idea)
I’m certain this is simple and I am just having a brain cramp but I’ve been trying things and google-binging for hours with no progress. Thank goddness for git to roll back.
Does anyone have any suggestions on the best way to go? I’m not needing someone to write my code, I just need pointed in the right direction.
Thanks