Why is may costom yield not working?

Hey guys,

I am currently working on a pause game system but I am having trouble while time.TimeScale is 0. Once the pause key is pressed it should set time.timeScale to 0 and then once it is pressed again set it back to 1. What am I doing wrong?

Main focus should be on making the WaitForRealSeonds work…

private var pressed : boolean;
private var paused : boolean;

function Update(){
	if(!pressed){
		if(Input.GetKeyDown(KeyCode.Pause)){
			if(!paused){
				Time.timeScale = 0;
				pressed = true;
				yield StartCoroutine(WaitForRealSeconds(0.5));
				pressed = false;
			}
			else{
				Time.timeScale = 1;
				pressed = true;
				yield StartCoroutine(WaitForRealSeconds(0.5));
				pressed = false;
			}
		}
	}				
}

function WaitForRealSeconds(time : float){
	var current = Time.timeSinceLevelLoad;
	
	while(Time.timeSinceLevelLoad - current < time){
		yield;
	}
}

You could do something like

#pragma strict

private var z : int;

function Start () {

}

function Update () {

if (Input.GetKeyDown ("p")){
	z = (z % 2) + 1;
	if(z == 1){
	Time.timeScale = 0;
        }else{
        Time.timeScale = 1;
		}
	}
}

You don’t set pause to true. So, the pause key only ever pauses, and never unpauses.