• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by jaymesfogarty · Jul 15, 2015 at 09:09 PM · musiccrossfade

Can't crossfade quickly between two audio tracks?

I'm working on my first platformer, (a retro pixel art sidescroller) and I'm trying to follow the great design philosophy of Portal 2, which had short audio loops fade in as the player jumped and soared through the air, and fade out again as they landed. I've got two audio tracks, one of which is a quiet and subdued one, the other one being more catchy and bombastic, to aurally reward the player for jumping and platforming.

Both of them sound bad at the same time though, so I need the more subdued one to play automatically at the start of the level (which I can do by ticking 'Play on Awake') and when the player jumps fade in second track and fade out the first track, and then when the player lands fade out the second track and bring back the first track.

I'm pretty sure that I need both of them to play in the background simultaneously to keep them in sync, one with no volume and one with high volume, so I've already set up two audio Snapshots, one called 'Static' for when the player is not jumping, and one called 'Active' for when the player is running.

I've already got what I believe is the right part of the beginning of the script, using the UnityEngine.Audio and calling out the two Snapshots, as well as setting up a transitional time, but I don't know how to create a crossfade based on when the character jumps, which then fades back when they land. I believe that I need to use a 'vSpeed' (or vertical speed) float, which I've attached to my character to figure out when the transitions would play, but after trawling the forums, I've not been able to find anyone else trying to accomplish this very specific behaviour.

Any guidance would be much appreciated! Cheers, and the script I've got so far is below!

using UnityEngine; using System.Collections; using UnityEngine.Audio;

public class MusicTransition : MonoBehaviour

{

public AudioMixerSnapshop ActiveSnapshot;

public AudioMixerSnapshop StaticSnapshop;

 public float TransitionTime = 0.5f;
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 aadithyabk · Jul 21, 2015 at 10:35 PM 0
Share

were you able to find a solution ?

avatar image jaymesfogarty · Jul 22, 2015 at 01:38 AM 0
Share

No, sorry. I'm new to Unity, so I made sure to re-look over the tutorials supplied for basic coding, audio, and snapshots, as well as other people's projects, but I couldn't find anything to help me out.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by IgorAherne · Nov 28, 2016 at 08:10 PM

https://forum.unity3d.com/threads/audiosource-cross-fade-component.443257/

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

AddMixingTransform and RemoveMixingTransform not working as I wanted 0 Answers

How to crossfade between two running animations while keeping them synchronized? 1 Answer

Zooming animation doesn't work 1 Answer

Animator.CrossFade or Animator.CrossFadeInInFixedTime does not play animation after crossfading. 0 Answers

Destroy "Don'tDestroyOnLoad" script in a specific scene ?? 3 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