Search Unity

Audio Remember position...

Discussion in 'Scripting' started by klindeman, Aug 24, 2005.

  1. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    I was wondering if it were possible to have Audio remember the position at which it stopped playing when you do audio.Pause(), so that when moving between scenes it will remember where it was when I do audio.Play(). I needed this when going from my Main Menu to the High Scores screen, since they play the same music.
     
  2. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    If you make sure the game object the Audio Source is attached to is not destroyed between level loads (by calling DontDestroyOnLoad on it or by placing it in scene 0), you should just be able to call Pause() and then Play() to resume it.
     
  3. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    ... and here's an update...

    Normally all objects are reset when loading a level, which resets the paused audio position.... so my suggestion above doesn't actually work.

    You will have to assign the 'DontDeactivateBeforeLevelLoad' tag to the game object containing the audio source to work around this.
     

    Attached Files: