Coroutine confusion

Although this may have already been answered elsewhere, I am still struggling to create delay’s in code execution and apparently Coroutines are the best way to do this.
In my example:
Previously written main code,
At a point where I decide I need to pause until continuing ,
Proceeding code.

I have tried using coroutines for the delay but I don’t want to have to put all of the code following the delay into the coroutine, just pause the execution of my main code before continuing with it.

I do understand that this is not the clearest explanation but any help is appreciated.

You can’t pause the execution of a normal function unless you use threads, but threads are not recomended in Unity since doing things outside the main thread is complicated.

If you don’t want to move all the code into the coroutine you can do this. Let’s say this is your code:

void SomeFunction() {
    //some code

    //you want a delay here

   //some more code
}

Turn that into:

void SomeFunction() {
    //some code

    StartCoroutine(Delay(2f,SomeMoreCode)); //delay of 2 seconds, pass the value you want
}

void SomeMoreCode() {
    //some more code
}

IEnumerator Delay(float seconds,UnityAction callback) {
    yield return new WaitForSeconds(seconds);
    callback();
}

This way you can delay any function for any amount of seconds from any other function in your code.