playMaker

Author Topic: playing music [SOLVED]  (Read 4652 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
playing music [SOLVED]
« on: November 25, 2013, 07:28:44 AM »
I found a very good music track that loops and wish to use this for my main splash screen.

But I want the music to continue from its last point when I load into the next scene.

So you here the music seamlessly.

I am unsure how to set this up.

Could someone please help.
« Last Edit: November 26, 2013, 02:01:59 AM by colpolstudios »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: playing music
« Reply #1 on: November 25, 2013, 12:38:36 PM »
I would try this:

Add a GameObject to your first loaded scene and call it MusicManager.
Add an FSM with Audio Play and Don't Destroy On Load actions. This will keep the MusicManager around when loading new scenes.

You might also have to store the current play time in a global variable if the music resets to the beginning on load. Use Get/Set Property with the audio.time property to store/restore the play time.

I haven't actually tried it, but it seems like something like this should work.

There might also be some clues in Unity Answers:
https://www.google.com/search?q=unity+play+music+across+scenes

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: playing music
« Reply #2 on: November 25, 2013, 05:42:23 PM »
a few minor changes needed.

audio play action not needed.

no need to store the current play time in a global variable.

Add a GameObject to your first loaded scene and call it MusicManager.

only add Don't Destroy On Load action.

In the inspector select the audio source

check play on awake and loop.

That's all you need if you wish the sound to play through all loaded scenes.

For me the sound did not stop and restart but played seamlessly.

I did not want this track to play at the same volume through every scene.

Using a global Int level set to zero

new state added to the MusicManager

int compare global level compare to 1

equal or greater than

every frame checked.

custom event lower music

new state lower the music

action: set audio volume I simply lower the value to 0.2.

The trick was the global value of level currently zero

one is added at runtime when you load the scene.

The MusicManager is still checking and moves you to the lower music state.

Sound is lowered instantly, a slow fade would be nice.

The volume begins at 1 and I set it to 0.2 this is noticeable.

Any advice on the best way to slowly fade from 1 to 0.2 would be very helpful




Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: playing music
« Reply #3 on: November 25, 2013, 05:59:26 PM »
You could use Float Interpolate or Ease Float to gradually change a float variable that you use to set the volume...

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: playing music
« Reply #4 on: November 26, 2013, 02:01:25 AM »
Ease float did not work however float interpolate DID WORK.