# Update() can not be a coroutine

**URL:** https://discussions.unity.com/t/update-can-not-be-a-coroutine/137112
**Category:** Questions & Answers
**Created:** [April 26, 2015, 3:10pm UTC](https://discussions.unity.com/t/update-can-not-be-a-coroutine/137112 "2015-04-26T15:10:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bobin115](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@bobin115](https://discussions.unity.com/u/bobin115)
#### Post date: [April 26, 2015, 3:10pm UTC](https://discussions.unity.com/t/update-can-not-be-a-coroutine/137112/1 "2015-04-26T15:10:40Z")

</div>

i get this error “Update() can not be a coroutine” this happens to me all the time how do i go about fixing this, here is my script;

```
 function Update() {
     if(Input.GetKeyDown("space"))
     yield WaitForSeconds(1);
         animation.Play ("jump_2");
 }

```

any help or amendments would be great

thanks

---

<div class="post-metadata">

### Author: ![DoTA\_KAMIKADzE](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dota_kamikadze/32/322455_2.png) [@DoTA\_KAMIKADzE](https://discussions.unity.com/u/DoTA_KAMIKADzE)
#### Post date: [April 26, 2015, 3:37pm UTC](https://discussions.unity.com/t/update-can-not-be-a-coroutine/137112/3 "2015-04-26T15:37:47Z")

</div>

You can’t do that in Update function, as the error says it can’t be coroutine. As instead create a custom coroutine function and call it on your space key. [Click here to check how to.](http://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html) You might also want to add some sort of cooldown countdown then or something.

Yet if you badly want that all to act in Update function then use [deltatime](http://docs.unity3d.com/ScriptReference/Time-deltaTime.html) and a variable that will count down your time, something like that:

```
float timer = 1f;
bool start = false;
void Update() 
{
    if (start)
    {
        timer -= Time.deltaTime;
        if (timer <= 0)
        {
            start = false;
            timer = 1f;
            animation.Play("jump_2");
        }
    }
    if (Input.GetKeyDown("space") && !start)
    {
        start = true;
    }
}

```

---

<div class="post-metadata">

### Author: ![LittleJohnGames](https://avatars.discourse-cdn.com/v4/letter/l/e5b9ba/32.png) [@LittleJohnGames](https://discussions.unity.com/u/LittleJohnGames)
#### Post date: [April 26, 2015, 4:06pm UTC](https://discussions.unity.com/t/update-can-not-be-a-coroutine/137112/2 "2015-04-26T16:06:51Z")

</div>

yield WaitForSeconds cannot be used under update. Try putting your jumping segment in a separate fuction and have the input line in the update funcion activate it

---

<div class="post-metadata">

### Author: ![LiamSorta](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/liamsorta/32/157500_2.png) [@LiamSorta](https://discussions.unity.com/u/LiamSorta)
#### Post date: [April 26, 2015, 4:06pm UTC](https://discussions.unity.com/t/update-can-not-be-a-coroutine/137112/4 "2015-04-26T16:06:47Z")

</div>

If you want to use WaitForSeconds you’ll have to call a coroutine.  
In your case, it’d be something along these lines:

```
function Update() {
  if(Input.GetKeyDown("space"))
      StartCoroutine(PlayAnim());
}

IEnumerator PlayAnim(){
    yield return new WaitForSeconds(1);
    animation.Play ("jump_2");
}

```
