How to wait in-game time while doing nothing and having the code still run normally?

I have any Army class that can have movement order and when they have one, they can only do a part of that movement per day and then they have to wait for an end of the day to move again. How can I implement code in a time manager that will basically do nothing until another day? The game is real-time.

One day is an in-game time and can take from 2 seconds to 0.125 seconds.

I tried doing while(currentDay == mainDate.D) but it just freezes my game.

public IEnumerator WaitOneDay()
{
    int currentDay = mainDate.D;

    while(currentDay == mainDate.D)
    {
        
    }
    yield return null;
}

mainDate is a game struct called GameDate and have three components - day, month and year and TimeManager class have oneof them called mainDate which tells you what current in-game date is and after some time in Update method will increment day by one.

private void Update()
{
    if (Route.ActiveRoute())
    {
        StartCoroutine(OnTheMove());
    }
}

private IEnumerator OnTheMove()
{
    StartCoroutine(timeManager.WaitOneDay());
    yield return null;
}

This is the script in the army that asks if the army have active movement orders and then try to move (the OnTheMove method would have actual code to do that but that is not my concern right now).
The WaitOneDay returns normal things when I don’t have the while loop in it (it saves the correct day in the currentDay).

Question is, why the game freezes? And how can I implement this?

Hello.

You cant use while there.

While makes the code stay inside all time, no other script will be running.

You should do a “if” and check if the condition is met do what you want, else, call the corutine again!