Toggle Slowmotion with timer not working

Hey i’m attempting to make a sort of slowmotion toggle for a project im working on.

Heres the code:

if(Input.GetKeyDown(KeyCode.V)){
	
		
		for(var i : int = 10; i > 0; i -= Time.deltaTime){
		Time.timeScale = 0.2;
		}
		
		
		
		if(myTimer <= 0){
			
			Time.timeScale = 1.0;
		
		}

It doesn’t work at all and I don’t know what to do. I’ve tried other ways of doing it but yeah… i’m stuck. I would appreciate a solution or simply a push in the right direction.

try this :slight_smile:

function Update () {
	if(Input.GetKeyDown(KeyCode.V)){
		Slowdown();
	}
}

function Slowdown() {
	for(var i : float = 10; i > 0; i -= Time.deltaTime * 10){
		yield WaitForSeconds (Time.deltaTime);
		Time.timeScale = 0.2;
	}
	Time.timeScale = 1.0;
}

note this: Time.deltaTime * 10. Multiplication is here just to speed it up.

Works perfectly. I would never have though of doing it like that. Thank you :slight_smile:

no problem, have a nice day :slight_smile: