- Home /
Can I pause parts of a game in Unity?
I have a pause menu that I built in Unity3D, using sprites and colliders. I can't pause the game using something like this:
if(gameObject == pauseButton)
{
Time.timeScale = 0;
}
because it pauses my pause menu too. I realize I should have built the pause menu with GUI objects so the game can be paused without pausing the GUI menu but I'm wondering if there is an easy workaround. Is it possible to assign pause menu elements to a layer and then enable the layer while the other layers are paused?
Also, is it generally a terrible idea not to use Unity GUI objects when building a gui?
It is unclear why you are having issues. Setting timeScale to zero does not stop Update() calls. So we really need your UI code to understand why you are having issues. If you are using Time.deltaTime to drive things in your UI, you can do something like this:
var myDeltaTime = Time.realtimeSinceStartup - prevRealTime;
prevRealTime = Time.realtimeSinceStartup;
Then you use myDeltaTime ins$$anonymous$$d of Time.deltaTime. This code will not pause when you set timeScale = 0.0;
As for the GUI class, lots of folks use it for their UI. The big downside for mobile is that every GUI UI element produces a drawcall, but for something like a menu that appear and is gone, this is not an issue. Third-party UI systems like EZGUI and NGUI use world objects and texture atlases for building UIs. It is rumored that the new UI system to be released in Unity 4.6 will be similar to NGUI.
$$anonymous$$y pause menu includes lots of animations so that is why I can't set timeScale to zero. I ended up using SetActive(false) on the parent GameObject that holds all pausable objects.
Answer by AndyMartin458 · Jul 15, 2014 at 09:18 PM
I think it might be overly complicated to build the pause GUI in this way. Is there extra functionality that you need other than standard unpause? There are tons of details and answers for what you are trying to do on this post. http://answers.unity3d.com/questions/7544/how-do-i-pause-my-game.html
The easiest option is to set the timeScale to 0 and draw your pause menu with Unity GUI. I know you are trying to avoid that very thing. The other solution is to manually pause all of the MonoBehaviour classes manually when the game is paused.
Your answer
Follow this Question
Related Questions
Access clicked button from the different function 1 Answer
Set the position of GUIBox 1 Answer
Error CS1519 1 Answer
Not working gui buttons 1 Answer
Distribute terrain in zones 3 Answers