- Home /
pause and restart button on android
I want to make a pause button, and also a restart one. I'd like to create Guitexture objects for them, and a script for each one. Can you help me with that script please!
Answer by paulaceccon · Mar 25, 2013 at 06:48 PM
You can create two buttons, one to pause the game and another to play it. To pause and restart the game, you can use the Time.timeScale, and set it to 0f to pause the game and to 1f to restart it. Of course you have to have some control variables to check either the game is paused or not, in order to show the buttons properly.
thank you for helping me. I have a question... how can i do the script for checking if the button is pressed or not? thanks a lot!
I didn't understand exactly what do you mean, but an idea is:
bool isPaused;
void Start ()
{
isPaused = false;
}
void OnGUI ()
{
if (!isPaused)
{
if (GUI.Button(Rect(10,10,50,50), "Pause"))
{
Time.timeScale = 0f;
isPaused = true;
}
}
if (isPaused)
{
if (GUI.Button(Rect(10,10,50,50), "Play"))
{
Time.timeScale = 1.0f;
isPaused = false;
}
}
}
I used that and it says Assets/Scripts/pause atm.js(1,5): UCE0001: ';' expected. Insert a semicolon at the end.