Update() can not be a coroutine.

I made this script that should make my car drive, but i after i made a waitforseconds inside function Update it came with this message: Script error (Car): Update() can not be a coroutine.

can someone help me how to fix this?

Here is the script:

#pragma strict

var spin = 3;
var topSpeed = 20;
var speed : float = 0.0;
var slowDown = false;

function Update ()
{

if(Input.GetButton(“FORWARD”))
{

speed = speed+0.2;
slowDown = true;

transform.Translate(Vector3(0,0,speed) * Time.deltaTime);

}

if(speed > topSpeed)

{
speed = topSpeed;

}

if(slowDown == true)  
 {
 
transform.Translate(Vector3(0,0,speed)   * Time.deltaTime);

  yield WaitForSeconds(speed % 4);

transform.Translate(Vector3(0,0,0)   * Time.deltaTime);


 

   
     }

}

Update() is the lifeblood of your game - the recurring pulse which causes your game’s vital systems to function.

If you were allowed to run the code you’ve written, the WaitForSeconds() function would have the effect of making your entire game stop for (speed % 4) amount of time during every frame in which (slowDown == true). Can you see why that wouldn’t make for a very good gameplay experience…?

WaitForSeconds doesn’t do what it says on the tin - its part of an elaborate feature called ‘coroutines’ that you neither understand or need.

Don’t use it, instead implement the functionality yourself. Set some value to the start time and check against it on every call to update to see if speed % 4 seconds have elapsed yet.