How can I use StartCoroutine() in Update()?

Hi,

I've been trying to make a cooldown for one of the attack function in Update().

However: IEnumerator wait (float waitTime) { yield return new WaitForSeconds (waitTime); }

and void Update() { yield return StartCoroutine(wait(5.0f)); }

doesn't work. Thank you very much!

You don't return StartCoroutine, you just call it:

IEnumerator Attack(float cooldown)
{
    /* Insert attack code here */
    weaponCooled = false;
    yield return new WaitForSeconds(cooldown);
    weaponCooled = true;
}

void Update()
{
    if (Input.GetKeyDown(KeyCode.Space) && weaponCooled)
    {
        StartCoroutine(Attack(5.0f));
    }
}

bool weaponCooled = true;

Note that this does not block the Update method -- it will immediately head onto the subsequent code.