When the user pushes the pause button, I do “time.timeScale = 0f;” However, by doing this, can the game still pop up a GUI pause menu and tell when the user presses a button on the Pause Button?
If it can’t, is there any other way to do a pause button? (I’m making the game for iOS).
and if I wanted to stop all objects that depend on CustomLayer, i just set it to 0 (as for animations, I updated my animators anim speed with the changed value as well via each objects animation-related script)
So, things like Physics and what not are impacted by the Time.timeScale directly.
Keep ‘gameplay’ on that. That being: ‘Time.time’ and ‘Time.deltaTime’ and anything dealing with Rigidbody.
When you slow the ‘Time.timeScale’ to 0, all those things slow down, but ‘Update’ and Coroutines still fire at the framerate. This is what ‘Time.realTime’ and ‘Time.realDeltaTime’ are for. They are uneffected by ‘Time.timeScale’.
This is why in my code my ‘custom’ times are based around the real time. You can then set those custom layers with the real time, and during the update code for say menus and what not, you use the custom layers.
That way you never have to worry about the impact of the timescale on your actual game physics logic.
Basically you can’t use timescale to pause. Everything will be slowed down by timescale. Its better to have a global variable, and inside update() function check this variable and then execute function or not.
For game physics, you need to delegate a event to this variable, when pause changed to true, set the objects velocity to 0. When pause changed to false, set objects velocity to the original state
Time.realDeltaTime is readonly, and it’s the amount of time that passed since last frame… it should seldom ever be 1f (if it were, your game is running at 1 frame per second).
You READ Time.realDeltaTime in places where you’ll need a delta time. Such as if you’re animate a button to move across the screen in an eased manner in the ‘Update’ function or during a Coroutine.
First off, sorry, it’s not Time.realDeltaTime (sorry, mistyping this whole time, I’m so used to using my SPTime wrapper that I’m used to typing real).
It’s Time.unscaledDeltaTime.
And it’s read only.
You can’t set it!
And if the value were to be read as 60f, that would be 1 frame per minute. The value that comes back from ‘deltaTime’ and ‘unscaledDeltaTime’ is the duration of time between frames. It’s just that unscaled version is uneffected by Time.timeScale.
The time between frames is super small. For instance most games are expected to run at 60fps, they look good there. That’s 1/60th of a second between frames. Or 0.016666666666…