Support => NGUI 3 Support => Topic started by: dev01 on February 21, 2013, 03:06:26 PM
Title: Pause Button
Post by: dev01 on February 21, 2013, 03:06:26 PM
How can I implement a game pause using an image button I have? I cant seem to find a script in the examples that will let me pause and un-pause my game.
I am no scripter! thats why I use ngui so an example script on how to do this would be appreciated. Thanks in advance!
Title: Re: Pause Button
Post by: lime-green.at on February 21, 2013, 06:23:30 PM
Set Time.timeScale to zero, on unpause just reset it to the value before you set it. (I got some problems with setting it to 1) http://docs.unity3d.com/Documentation/ScriptReference/Time-timeScale.html
Title: Re: Pause Button
Post by: tydygunn on February 21, 2013, 07:55:54 PM
There are much better ways to do this, but if you're not a scripter then setting the timescale to 0 is probably your best bet.
C#
void OnClick()
{
if(Time.timeScale==1) Time.timeScale=0;
else Time.timeScale=1;
}
If you make a C# script with that function and toss it on your button it should work. Like I said though, this could mess you up because Unity's Time is used for a lot of different things and stopping it's flow could stop your other scripts from functioning if they reference Time.time or anything similar.
Title: Re: Pause Button
Post by: redhawk on February 22, 2013, 05:09:35 PM
I've used the below code inside JavaScript in unity. Haven't attached it to an NGUI object yet. Also, in addition to the below, I set my Start function to Time.timeScale=1;
if(Time.timeScale==0)
{
//I also changed my button to white for not paused
Time.timeScale=1;
}
else
{
//I also changed the color of my Button to Red for paused