- Home /
Question by
Catlinman · Nov 20, 2012 at 03:05 PM ·
yieldtime.timescale
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;
}
}
Comment
Answer by Griffo · Nov 20, 2012 at 03:28 PM
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;
}
}
}
Answer by Owen-Reynolds · Nov 20, 2012 at 10:13 PM
You don't set pause to true. So, the pause key only ever pauses, and never unpauses.
Your answer
![](https://koobas.hobune.stream/wayback/20220613084159im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
yield WaitForRealSeconds 1 Answer
Calling a function after game over to retry 0 Answers
Mysteries of yield 1 Answer
C# yield error 3 Answers