Drewson
1
I have made a functioning Pause Button by applying this code to a button:
function OnMouseDown ()
{
Time.timeScale = 0;
audio.pitch = 0;
}
There are a few problems.
- I have to put the audio source on the button for the code to work as it is now.
- Other audio sources in the scene are unaffected.
- I can’t hit the button again to “Unpause”
I want a Pause button that does the following:
Sets the timescale to 0 when hit.
Sets the pitch to all audio sources in the scene to 0 when hit.
Reverses all of the above when hit again.
Can someone show me how to make the button support being hit over and over to reverse the effect each time?
Eiznek
2
Just make a boolean that knows which state the pause is in…
Make a class scope variable
Private bool isPaused;
Then in your button you can just do
If(!isPaused)
{
isPaused = true;
//pause
}
else
{
isPause = false;
// unpause
}
Drewson
3
When I write the script that establishes the boolean, do I then bind it to the button or just an empty gameObject in the scene?
Sorry, this is just a hair above my capabilities.
Also - would the code for the boolean definition be:
using UnityEngine;
Private bool isPaused : MonoBehaviour
{
}
please note, my knowledge of scripting is limited to downloading and modifying scripts. 
use it in your current script…
var isPaused:boolean = false;
function OnMouseDown ()
{
if(!isPaused)
{
isPaused = true;
Time.timeScale = 0;
audio.pitch = 0;
}
else
{
isPaused = false;
Time.timeScale = 1; // or whatever your normal values may be
audio.pitch = 1;
}
}
so yeah, just add what he said to your current code
[edit]
I normally code in c# so I hope I did the correct unityscript syntax… if not, it should be close…
[/edit]
Drewson
5
Thanks novashot, that works a charm!