How do i make a delay in milliseconds?

Hello.

I’ve been using unity for quite a while now and as far as i can remember i allways had a problem with using the yiel Waitforseconds(); command. I’ve figured it out recently and now it works fine, but i realised thet now i need a more precise time.
Is there a way to make a delay that waits for inputed miliseconds?
thanks

You really can’t make a specific small delay. Coroutines run at most every frame. WaitForSeconds(X) really says to keep skipping frames until at least X time has passed. In other words, if you’re at 50FPS, Wait rounds up to the nearest 0.02.

As a quick test, can try a Wait loop using 0.01, 0.001, 0.0001 and see if it makes any difference.

WaitForSeconds take a float for a argument/parameter. So if you wanted to wait one second:

// C#
yield return new WaitForSeconds(1);

// js
yield WaitForSeconds (1);

but if you wanted to wait for 1 millisecond:

// C#
yield return new WaitForSeconds(0.001F);

// js
yield WaitForSeconds (0.001);

Try this:

float delayInMs = 0.01f;
float ms = Time.deltaTime;

while(ms <= delayInMs )
        {
            ms += Time.deltaTime;
            yield return null;
        }


//Do your stuff