- Home /
resuming Time.timeScale Problems
So i have a pause button working on a sidescroler. it pauses and resumes the game using Time.timeScale. the problem is that when i resume the game, everything moves and reacts slower. i can't pick up the powerups (collision based) and the enemy takes a sec to react to the controler passing him, do damage, and stop while hitting him.
Here is the script for the pausing. the powerups and enemy movement are on different scripts:
var thePauseButton = GUI.Toggle(Rect ((Screen.width)-((theButtonWidth*3)), theButtonSpace*-1, theButtonWidth, theButtonHeight), thePauseButton, "Pause");
if(thePauseButton) { print("Pause"); PauseTheGame (0); gamePaused = true; }
if (Input.GetKey (KeyCode.Escape) && gamePaused) { print("Resume"); //Time.timeScale = 1.0; PauseTheGame (1.0); gamePaused = false; }
function PauseTheGame (theRateScale) { Time.timeScale = theRateScale; Time.fixedDeltaTime= theRateScale; theRate = theRateScale; }
On a side note, i was under the impression that a timescale of 0 would pause everything in the scene. but the enemy still moves and i can still instiantiate prefabs (a bullet) but it won't move.
Sorry about the code, i can't seem to get it to format correctly.
There's a little button with 1s and 0s on, select all of your code then click that
i did, but it wouldn't format it any better than how i have it here for some reason. i've done it before, it just doesn't like me today.
Answer by efge · Apr 08, 2011 at 08:44 PM
Maybe it is because you are mixing Ints with Floats? You could try to declare the variable "theRateScale" and call it accordingly:
PauseTheGame (0.0);
function PauseTheGame (theRateScale : float) { ... }
i did have theRate declared as and int. but after i changed it, it didn't make a difference.
Answer by Victor 1 · Apr 09, 2011 at 01:31 AM
Insted of Time.timeScale you can use a varibles that checks if the game if pause or not, and if it paused it dosent move charater,enemies etc.
void OnPauseGame () { paused = true; }
void OnResumeGame () { paused = false; }
void Update (){ if(!paused){ //do stuff } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613121642im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
disabling a script (MouseLook) 5 Answers
Coroutine randomly stops and continues after pausing and unpausing game 2 Answers
ManaBar plus pause 1 Answer
Problem with Pause and WaitForSeconds 2 Answers
i have some pausing errors 1 Answer