- Home /
Don't start the audio from the beginning
Hi; How can I stop the audio to play from the beginning when the scene loaded again. I have a scene named x which has a background music. In the middle of the game the player will be lead to another scene (Name it y) for just some seconds and the s/he will be led to the x. I want to play the music in x from the beginning just the first time player enters that scene, and the next times the music continues from where the player left scene x. I used pausing and don't Destroy functions. However,they didn't solve the problem and they just add new music to the song. I mean I had more than one audio played in one scene. How can I make the music to start from where the scene was left. Thanks in advanced and sorry if I couldn't explain the main problem.
Answer by Tseng · Dec 31, 2011 at 03:12 PM
You can use the AudioSource properties time
and timeSamples
to set the time. Of course you have to save it before loading scene y.
http://unity3d.com/support/documentation/ScriptReference/AudioSource-time.html http://unity3d.com/support/documentation/ScriptReference/AudioSource-timeSamples.html
Aren't those two properties read-only? What do you mean "save it before loading scene y"?
Answer by tatelax · Dec 31, 2011 at 12:49 AM
Uncheck the options "Play on awake".
I unchecked it, and now the audio file doesn't play at all.What should I do?
Attach the audio clip to your main camera. You need to make a script which turns the audio on when you want it to. Attach that script to your camera. See the link below:
http://unity3d.com/support/documentation/ScriptReference/AudioSource.Play.html
I have an audio source and an audio listener which is attach to my camera. I have a script attach to my audio source, but the audio.play() doesn't work. I once try to add it to start function and uncheck the play on awake. But it didn't work.
at function Start(){
audio.enable = false;
}
//where the scene was left
audio.enable = true;
is it somethings like this
Your answer
Follow this Question
Related Questions
audio.ignoreListenerPause 1 Answer
How to continue paused audio? Is there a special function? 1 Answer
Problem with audio after leaving pause menu 1 Answer
Audio keeps playing when paused 1 Answer
Using Pause and sound on/off in Toggle 2 Answers