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 Vergil · Jul 17, 2013 at 11:44 AM · music

How to script a MusicPlayer?

Hi

I have two tracks of music(an intro track and a loop track),i need and a script that plays the Intro track once(as the game starts) and following it(exactly after it's ending) I want the loop track to begin and fell in loop.

Can anybody help me with that?

Any helps would be appreciated!

Comment
Add comment
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

2 Replies

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

Answer by sfc.itzhak · Jul 17, 2013 at 12:13 PM

here you go this is 1 way

     AudioSource MpPlayer;
     AudioClip FirstClip;
     AudioClip SecondClip;
     // Use this for initialization
     void Start () {
         MpPlayer.clip = FirstClip;
         MpPlayer.loop = false;
         MpPlayer.Play();
         StartCoroutine(WaitForTrackTOend());
     }
 
     IEnumerator WaitForTrackTOend()
     {
         while (MpPlayer.isPlaying)
         {
 
             yield return new WaitForSeconds(0.01f);
             
         }
         MpPlayer.clip = FirstClip;
         MpPlayer.loop = true ;
         MpPlayer.Play();
        
     }


edit shit should work now i forgot to call the second function

Comment
Add comment · Show 6 · 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 Vergil · Jul 17, 2013 at 01:30 PM 0
Share

Tnx for helping ,this script plays the First clip But the second is not being Played(I also tried changing the firstClip to SecondClip in IEnumerator method but it doesn't working)

avatar image sfc.itzhak · Jul 17, 2013 at 02:39 PM 1
Share

ahh i forgot somthing StartCoroutine(WaitForTrackTOend());

    AudioSource $$anonymous$$pPlayer;
     AudioClip FirstClip;
     AudioClip SecondClip;
     // Use this for initialization
     void Start () {
         $$anonymous$$pPlayer.clip = FirstClip;
         $$anonymous$$pPlayer.loop = false;
         $$anonymous$$pPlayer.Play();
  StartCoroutine(WaitForTrackTOend());
     }
  
     IEnumerator WaitForTrackTOend()
     {
         while ($$anonymous$$pPlayer.isPlaying)
         {
  
             yield return new WaitForSeconds(0.01f);
  
         }
         $$anonymous$$pPlayer.clip = FirstClip;
         $$anonymous$$pPlayer.loop = true ;
         $$anonymous$$pPlayer.Play();
  
     }
avatar image Vergil · Jul 17, 2013 at 03:40 PM 0
Share

It is Working Totally Fine , thanks Friend! ;)

avatar image sfc.itzhak · Jul 17, 2013 at 06:02 PM 0
Share

sure thing if you can accept the answer. above

avatar image sfc.itzhak · Jul 21, 2013 at 03:59 PM 0
Share

can you accept the answer so ppl will know there is answer to this question?

Show more comments
avatar image
-1

Answer by hajiyeve92 · Jul 14, 2017 at 10:37 AM

please follow link bellow and download asset. -best example for music player(almost everything included) https://www.assetstore.unity3d.com/en/#!/content/90589 Don't forget to leave your review

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 Riiich · Feb 02 at 11:44 AM 0
Share
  1. This doesn't help at all

  2. The link is broken

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to make the music better 1 Answer

Destroy "Don'tDestroyOnLoad" script in a specific scene ?? 3 Answers

Music trackers and iOS 0 Answers

adding music to the main menu screen 0 Answers

.wav file not working 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