- Home /
How to Appease a pause menu in a game that changes it's time scale?
I am working on a games pause menu, it works fine, but my pause script conflicts with other scripts in the game. i have it so when the player hits a certain object, the time scale changes. the problem i am having is with my pause menu script, it goes something like this...
if (Input.GetKeyDown(KeyCode.Z)){ isPaused != isPaused; } if (isPaused == true){ Time.timeScale = 0; }else{ Time.timeScale = 1; }
how could i change it so the else statement reverts the time scale back to what it was before isPaused = true?
Answer by nicolasjr · Apr 14, 2014 at 02:00 PM
you create a private variable that will hold the previous value. Let's say:
private float _previousTimeScale;
than, inside the if condition, you can do something like:
_previousTimeScale = (Time.timeScale != 0) ? (Time.timeScale) : (_previousTimeScale);
What this last line does is to simply verify if the current time scale is different than 0, if it is, it'll save the time scale value, otherwise, it won't.
then, you assign it to your time scale:
if (isPaused == true){
Time.timeScale = 0;
}else{
Time.timeScale = _previousTimeScale;
}
Makes sense?
Your answer
Follow this Question
Related Questions
Pause menu... Isn't pausing everything... 1 Answer
Pause menu doesn't pause everything 0 Answers
Stop force from being applied during pausescreen 1 Answer
how to pause the mouselook script during pause? 1 Answer
hi i just got the ultimate fps camera and it is not compatible with pausemenus 0 Answers