|
I'm using the standard trick of setting Time.timescale = 0 to pause my game. Then I present buttons when paused to restart the level, go to the main menu, mute, shop, etc. I want to play a consistent button sound across all UI buttons when clicked, but when in game pause, my button clip doesn't play immediately. I assume that Time.timescale=0 tells Unity to also pause new audiosources. Is there any way around this and to make them play immediately? I can't find anything on the forum or in documentation. Thanks.
(comments are locked)
|
|
AudioSources play independently of Time.timeScale - probably the code that should call Play() is being stopped when timeScale becomes 0. If you use the code below, the sound assigned to audio.clip will be played anytime the button pause is clicked (attach this code to the object that has the AudioSource):
private var pause = false;
private var lastValue = false;
function OnGUI(){
pause = GUI.Toggle(Rect(10,10,200,60), pause,'Pause');
if (pause)
Time.timeScale = 0.0;
else
Time.timeScale = 1.0;
if (pause != lastValue){ // if pause changed...
lastValue = pause;
audio.Play(); // play the sound
}
}
Thanks! Sorry for replying so late! I have to get in the habit of trying small examples to prove/disprove. My bad. I'm too focused on just getting my app out the door after many months. I don't think my code is getting paused as my callbacks from buttons are being issued (EZGUI) and my calls to Play() are being made. Something else must be going on. Cheers.
Apr 18 '12 at 10:47 PM
jackpile
(comments are locked)
|
