Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

iOS Requirement (A10.16) Ensure that when iTunes Radio is playing, Game Music must be set to “Off” automatically 2 Answers

Continue Playing Music on Load Level 0 Answers

Stream music from a folder? 1 Answer

Music volume decreases after one loop 1 Answer

how to make the music better 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