Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Sarthak123 · Oct 23, 2014 at 09:17 AM · playmusicplaying

Help : Playing Multiple Background Musics !

I need help in playing multiple background musics, i have 3 music clip, i attached them to 3 different objects in my scene, i have one audio mangaer script in my scene which works like this,

 var ambient1 : GameObject;
 var ambient2 : GameObject;
 var ambient3 : GameObject;
 
 
 function Start () {
 ambient1.audio.Play();
 }
 
 function Update () {
 if(!ambient1.audio.isPlaying)
     {
         ambient2.audio.Play();
         if(!ambient2.audio.isPlaying)
             {
                 ambient3.audio.Play();
                     if(!ambient3.audio.isPlaying)
                         {
                             ambient1.audio.Play();
                         }
             }
     }
 }

but it only plays first ambient, it does not play anyother ambient... is there something i am missing? and also, how can i add a delay of 2 min between them?

Comment
Add comment · Show 2
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 Ali-hatem · Oct 23, 2014 at 09:50 AM 0
Share

are your music is loping i mean first ambient keep playing

avatar image Sarthak123 · Oct 23, 2014 at 10:24 AM 0
Share

no its not looping

1 Reply

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

Answer by _Yash_ · Oct 23, 2014 at 09:50 AM

It actually plays second but it keeps starting second track again n again so it feels like nothing is playing after first track.

You can make 3 coroutines for playing each track and add a delay according to clips lengh.

Something like

 void Start(){
     StartCoroutine(amb1());
 }

 Ienumerator amb1(){
     //play track 1
     //add delay, yield return new waitForSeconds(t1time);
     StartCoroutine(amb2());
 }

 Ienumerator amb2(){
     //play track 2
     //add delay, yield return new waitForSeconds(t2time);
     StartCoroutine(amb3());
 }

 Ienumerator amb3(){
     //play track 3
     //add delay, yield return new waitForSeconds(t3time);
     StartCoroutine(amb1());
 }
Comment
Add comment · Show 1 · 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 Sarthak123 · Oct 23, 2014 at 10:24 AM 1
Share

@Yash oh i get it, what you said, but ins$$anonymous$$d of using co-routine(since i dont know much about them), i used boolean variables and AudioClip Ins$$anonymous$$d of GameObject, and it works.. i added the delay with audio.PlayDelayed()

 var ambient1 : AudioClip;
 var ambient2 : AudioClip;
 var ambient3 : AudioClip;
 var playedFirst : boolean = false;
 var playedSecond : boolean = false;
 var playedThird : boolean = false;
 
 function Start () {
 audio.clip = ambient1;
 audio.Play();
 playedFirst = true;
 playedSecond = false;
 
 }
 
 function Update () {
 
 if(!audio.isPlaying)
 {
 
     if(!playedFirst)
     {
         audio.clip = ambient1;
         playedFirst = true;
         playedSecond = false;
         audio.PlayDelayed(120);
     }
     else if(!playedSecond)
     {
         audio.clip = ambient2;
         playedSecond = true;
         playedThird = false;
         audio.PlayDelayed(120);
     }
     else if(!playedThird)
     {
         playedThird = true;
         playedFirst = false;
         audio.clip = ambient3;
         audio.PlayDelayed(120);
     }
 }
 
 
 }

This also worked.

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 to make music play always without duplicates? 0 Answers

Can't get my sound to work.. 1 Answer

Getting my 2D sound trigger to play only once 1 Answer

Is there any way to make the headphone pause/unpause controls work when the Unity app is running, to pause/unpause background app(apple music/google music) music? Android app. 0 Answers

Music play when MOVING.. 2 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