UPDATE 2 - FIX
I fixed the issue from this thread http://forum.unity3d.com/viewtopic.php?t=16981 that jarleif had by creating a scene that gets loaded before my old first scene AS THE NEW FIRST SCENE :). The new scene should be exactly the same as the old scene, so hopefully none of you have a crazy gui oriented old scene. That being said what you do now is create a script that has a COMPRESSED music file. At least that’s what I have tested. You set it to play on Start(). Now when you run the app it should play in the editor which is ok! It will not play on your device (iphone/ipod touch). Now THE IMPORTANT PART. If you have an options menu in your game and have a “quit” button, then when the user chooses to quit you need load the “old” scene. This will bypass the “new” scene you added which bypasses its Start() function which will not play that sound. This is the desired effect and the only real solution I have at the moment having only about 3 hours of sound programming with unity iPhone. Hope this helps community! Happy developing!
I am still wondering how to use the audio.time variable properly for future projects.
UPDATE 1 - FIX
WOW. I have been up way too long tonight. I fixed the issue below by simply not doing anything to the music when the menu is pressed lol. The music plays while in the menu and properly keeps playing on resume and resets when the user clicks restart. Still having the issue of the “first level loaded sound doesnt play” issue that I have read about in another thread.
Here is the ‘final’ code that is sitting in my project that does what I need it to do. I can’t show the entire script or that would be cheating :).
// Options icon.
if(GUI.Button(Rect(10, (Screen.height/1.25), 50, 50), "", optionsStyle))
{
audio.PlayOneShot(buttonSound);
pauseFlag = true;
Time.timeScale = 0.0;
m_state = 1;
}
//-----------------------------------------------------
// Resume button.
if(GUI.Button(Rect((Screen.width/2)-(brect.width/2), (Screen.height/2)-(brect.height*1.5)-5,
brect.width, brect.height), "", resumeStyle))
{
pauseFlag = false;
Time.timeScale = 1.0;
audio.PlayOneShot(buttonSound);
m_state = 0;
}
Hello everyone!
Chugging away on some sound stuff for the game, which is coming along incredibly well. I have an issue right now when I enter my options menu. I am able to pause my compressed .mp3 when it enters the options menu, but when I hit my resume button the song does not play at all. I essentially lose the game music.
I am using unity iPhone 1.0.1
This code works perfectly in the editor but not on the iPod touch:
//Options icon
if(GUI.Button(Rect(10, (Screen.height/1.25), 50, 50), "", optionsStyle))
{
audio.Pause();
audio.PlayOneShot(buttonSound);
pauseFlag = true;
Time.timeScale = 0.0;
m_state = 1;
}
//----------------------------------------------------
// Resume button.
if(GUI.Button(Rect((Screen.width/2)-(brect.width/2), (Screen.height/2)-(brect.height*1.5)-5,
brect.width, brect.height), "", resumeStyle))
{
pauseFlag = false;
Time.timeScale = 1.0;
audio.PlayOneShot(buttonSound);
audio.Play();
m_state = 0;
}
This was the alternative method that I tried using audio.time. musicPos is just a variable I created to hold the sound’s position after it pauses. I think I might be using it wrong so maybe someone can give it a shot:
// Options icon.
if(GUI.Button(Rect(10, (Screen.height/1.25), 50, 50), "", optionsStyle))
{
audio.Pause();
musicPos = audio.time;
audio.PlayOneShot(buttonSound);
pauseFlag = true;
Time.timeScale = 0.0;
m_state = 1;
}
//-----------------------------------------------------
// Resume button.
if(GUI.Button(Rect((Screen.width/2)-(brect.width/2), (Screen.height/2)-(brect.height*1.5)-5,
brect.width, brect.height), "", resumeStyle))
{
pauseFlag = false;
Time.timeScale = 1.0;
audio.PlayOneShot(buttonSound);
audio.time = musicPos;
audio.Play();
m_state = 0;
}
Also, I am having the issue where my first level music doesn’t load, but it will load when i enter my options menu and hit ‘restart’. This is an odd time for me…As always thanks in advance.
~corey~