Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cgraf1 · Mar 08, 2016 at 12:44 AM · audioaudiosourceaudioclipmusic

How to stop music from restarting when reloading scene it began?

Hello everyone. I am making a small 2D game, but am having some trouble with controlling the music. I have a menu track and a gameplay track. The menu track loads on a quick scene before the menu pops up. Once in the menu, I can go through all the different menu scenes without the music changing or restarting.

Once the player hits "Play" the gameplay track starts. Upon their death, a new scene comes up where they can choose to "Retry" or "Quit." Here is where the issues come up. If they hit "Quit", it goes back to the menu continuing to play the gameplay track. If they hit "Retry", it goes back to the game, but the gameplay track restarts from the beginning. Does anyone know how to solve this issue?

Note: I am using the popular Singleton solution found from this post http://answers.unity3d.com/questions/11314/audio-or-music-to-continue-playing-between-scene-c.html.

It is not a track duplication issue. I would like the menu track to go continuously and loop until the Player hits "Play" and then the gameplay track to go continuously and loop until the player hits "Quit", then back to the menu where the menu track begins again. Any help for this would be greatly appreciated. Thank You!

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flashframe · Mar 08, 2016 at 01:15 AM 0
Share

Sounds like you need to check if the audio clip is already playing before starting it

avatar image cgraf1 flashframe · Mar 08, 2016 at 01:25 AM 0
Share
 static public void PlayGame$$anonymous$$usic(){
 
         if(instance != null){
 
             if(instance.source != null){
                 instance.source.Stop();
                 instance.source.clip = instance.play$$anonymous$$usic;
                 instance.source.Play();
             }
         }else{
             Debug.LogError("Unavailable $$anonymous$$usicChange component");
         }
     }

Is that not what this is doing?

avatar image flashframe cgraf1 · Mar 08, 2016 at 01:40 PM 1
Share

@cgraf1 Sorry, Unity never sends me notifications, so I only saw your reply this morning.

If I understand your intent correctly, you'd like the music not to restart when you "Retry" your level.

Your PlayGame$$anonymous$$usic() method always stops the music before playing it. I'm suggesting that you check to see if the music is playing already before you stop and restart it. Like this:

              if(instance.source != null && !instance.source.isPlaying){
                  instance.source.Stop();
                  instance.source.clip = instance.play$$anonymous$$usic;
                  instance.source.Play();
              }

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

C sharp cant play Audio 2 Answers

Unity Unable to Reassign Audio Clip 1 Answer

Unity 5 low audio volume 1 Answer

How can I check the scene and play audio accordingly? 1 Answer

Why does the audio sound different than the original ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges