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 Cartola · Oct 07, 2015 at 07:09 PM · animationsoundsong

Music does not play between scenes

Hi guys, I was designing a scene of my project and everything worked normally, including the sound, but I realized that the editor and build the sound that plays in loop located on the ground scene does not. Only in scenes exchanges it does not work, starting from the actual scene it usually works. Can anyone tell the point?

Comment
Add comment · Show 1
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 Cartola · Oct 07, 2015 at 08:27 PM 0
Share

But what happens is that any sound from the scene after the menu scene is played, I only realized this when I build, because before I just compiling this single scene and sounds worked, but when I build the project with every scene only the menu music is played.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jessespike · Oct 07, 2015 at 07:52 PM

Have you tried DontDestroyOnLoad?

Comment
Add comment · Share
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
0

Answer by engieelec · Oct 08, 2015 at 12:20 AM

     public static MusicManager instance = null;
     private AudioSource audioSource;
 
     void Awake()
     {
         if(instance == null)
         {
             instance = this;
         }
         else if(instance != this)
         {
             Destroy (gameObject);
         }
         
         DontDestroyOnLoad(gameObject);
 
         audioSource = GetComponent<AudioSource>();
 
     }

Create a "MusicManager" singleton and instantiate it in your first scene. Add an audio source to it and a collection of music clips that you would like to play. Also add a few methods to indicate which clip to play.

Comment
Add comment · Show 2 · Share
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 Cartola · Oct 08, 2015 at 12:26 PM 0
Share

@engieelec I do not understand: when changing scene all previous scene objects are destroyed and the new instanced scene, why the need for a $$anonymous$$usic$$anonymous$$anager? It also gave error on this line: public static $$anonymous$$usic$$anonymous$$anager instance = null; (I have not used it, I tried to create a GameObject in the first scene with that name and did not work)

avatar image engieelec · Oct 08, 2015 at 07:12 PM 0
Share

This singleton instance will not be destroyed if a scene is changed. It will persist.

  1. You would need to create a script called $$anonymous$$usic$$anonymous$$anager

  2. Add the above code

  3. Create an empty object in your scene and add a script to it

  4. Add an Audio Source to the object

  5. Create a collection of Audio Clips to play (like an array) and make it public

  6. Add all of your sound clips to the collection

  7. Create a prefab of the $$anonymous$$usic$$anonymous$$anager object and delete the original one in your scene

Now, you can instantiate the $$anonymous$$usic$$anonymous$$anager in your first scene:

  1. Create an empty game object called Launcher or some other name

  2. Add a script to it with this:

    public class Launcher : $$anonymous$$onoBehaviour {

      public GameObject $$anonymous$$usic$$anonymous$$anager;
     
         void Awake()
         {
             Instantiate($$anonymous$$usic$$anonymous$$anager);
         }
     }
    
    
  3. Drag the $$anonymous$$usic$$anonymous$$anager prefab on

  4. Change your scenes

Notice that the "Launcher" is gone but "$$anonymous$$usic$$anonymous$$anager" persists between scenes.

You can go back to your $$anonymous$$usic$$anonymous$$anager script and add methods to play music clips and then call the $$anonymous$$usic$$anonymous$$anager instance elsewhere in your implementation like:

$$anonymous$$usic$$anonymous$$anager.instance.doSomeThing();

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

How can I stop animation and sound clip looping on tapCount 1 Answer

Play animation and sound when GUI button is pressed 1 Answer

multiple Animation Events in an Animation 0 Answers

NPC reaction by sound external o BPM 0 Answers

playing realtime sound in unity's animation window? 1 Answer


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