how do I use wait for seconds c#

I’m building a 2d platformer and have just added a projectile attack to my player character. The only problem is the projectile spawns immediately when prompted, but id like it to spawn about 0.25 seconds after the keypress so to align with the throw projectile animation. It appears to me waitforseconds would be the most compact solution, but I cant seem to achieve the desired result.

if (Input.GetKeyDown(KeyCode.Tab) && Time.time - throwTime > 0.40) {
myAnimator.SetBool(“throw”, true);

    throwTime = Time.time;

      CastProjectile(0); //id like to delay CastProjectile
    }

as shown I’ve got a time condition limiting when a keypress can be accepted to at least 0.40 seconds after the last keypress so a delay won’t conflict with the next delay

So the syntax of WaitForSeconds goes:

Call:

StartCoroutine(SpawnAfterDealy(0.25f));

Function:

IEnumerator SpawnAfterDealy(float delay)
{
    yield return new WaitForSeconds(delay);
    //whatever you want to do
}

use WaitForSeconds for scaled time and WaitForSecondsRealtime for realtime

Hope this helps :slight_smile: