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
1
Question by DolphinDudeOne · Jul 14, 2014 at 12:46 AM · audioaudiosourcemusicaudiolistener

Change music during chase

I'm trying to make the music change whenever the player is being chased by "Demon". The music being played normally is "CreepyMusic" and the chase one is called "HorrorChase". Both are attached as 2D sounds to the player alongside an audio listener but I have no idea of how to alternate them. How could I do this?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rutter · Jul 14, 2014 at 12:46 AM

Assuming you have a reference to each AudioSource (possibly set from the inspector), you can tell one to Stop and the other to Play:

 //two AudioSource variables
 defaultMusic.Stop();
 chaseMusic.Play();

If you want to be fancy about it, you could "fade out" one track, or "fade in" the other, by setting their volume over multiple frames. Tweening libraries such as iTween can be very helpful for that.

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 DolphinDudeOne · Jul 14, 2014 at 01:40 AM 0
Share

So far I have this:

 #pragma strict
 
 var default$$anonymous$$usic : AudioClip;
 var chase$$anonymous$$usic: AudioClip;
 
 function OnTriggerEnter() {
 default$$anonymous$$usic.Stop();
 chase$$anonymous$$usic.Play();
 }
 
 function OnTriggerExit() {
 chase$$anonymous$$usic.Stop();
 default$$anonymous$$usic.Play();
 }

But it says that 'Stop' and 'Play' are not members of 'UnityEngine.AudioClip'.

avatar image MagicoCreator · Jul 14, 2014 at 09:16 AM 0
Share

and that's because they aren't, you should use 2 AudioSources with the clips attached to them (or use one and change its clip value, (but if you use 2 you can fade out one and fade in the other one ins$$anonymous$$d of abruptly cutting them off)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Stereo Mix as Input? 1 Answer

Can not play a disabled audio source 2 Answers

Multi Channel Audio 4 Answers

How do I only start the audio when player is at max distance 1 Answer

Audio from new scene begins half way through loading. 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