Time.timeScale, yield, then Time.timeScale?

I’d like to slow time for a matter of seconds then resume at normal speed. I’m not sure what I should look into to achieve this. I haven’t found any tutorials on the subject. Here’s my (non-working) code:

var delay : float = 7;

function Update () {

if(Input.GetButtonUp("Jump")){

    Time.timeScale = .01;
    yield WaitForSeconds(delay * Time.timeScale);
    Time.timeScale = 1.0;
	
	}
	
}

I get the error “Update can not be a coroutine.” Any advice would be much appreciated. Thank you!

Update runs every frame, so simply keep track of a timer. During Update(), add Time.deltaTime to your timer. (Or subtract if you’d rather count down.)

I’m not sure whether Time.deltaTime changes speed based on Time.timeScale. If it doesn’t, that’ll be good enough. If it does, then do Time.deltaTime/Time.timeScale.

When your timer reaches the destination, return Time.timeScale to normal.

Thanks for the help. This is what I have so far. It works as a functionUpdate when I start the game, but I need to call the function from another script, so it can’t be functionUpdate (unless it can …I’m a noob, fyi).

var slowDelay : float = 2;
var SpeedOfLight : float = 3;
var SOLduration : float = 200;

function LightSpeed() {

Time.timeScale = .1;

slowDelay -= Time.deltaTime/Time.timeScale;
SOLduration -= Time.deltaTime/Time.timeScale;


if(slowDelay<=0){

    Time.timeScale = SpeedOfLight;
	
	}
	
	
if(SOLduration<=0){

    Time.timeScale = 1.0;
	
	}
	
	
}

When called from my other script, timeScale is set to .1, but then just sits at that speed forever. Any ideas?

Do you call it every frame?

There’s an if statement in another script (which is called every frame) essentially stating:

if power > 100
sendmessage(LightSpeed)
power = 0

I’m at work right now, so I can’t test this, but maybe the order is wrong? If i reset power to 0 THEN do the sendmessage, maybe that would work? I’m still stumped til I get home and try.