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 Android Matt · Sep 08, 2012 at 04:44 AM · animationaudiofadecontinuousjet

Fade audio in and out for Jet Engine

Hi,

I would an audio clip to quicly fade-in and then play (continous sound) when a certain key is pressed, and then for the sound to quickly fade-out and pause when the key is released. I have attempted to get this to work with animation, but the fade-out part doesn't work.

Any ideas?

I created two animations, one which faded the volume in, and the other faded it out. I tried to call these at the relevant times in my code. The audio clip is assigned to the audio source in the inspector.

My attempt at code:

     if (Input.GetButtonDown( "Horizontal" ) || Input.GetButtonDown( "Vertical" ) ){
         animation.Play("animationJetOn");
         if(jetAudio){
             audio.Play();
         }
 
     }else if ( !Input.GetButton( "Horizontal" ) && !Input.GetButton( "Vertical" )  && audio.isPlaying){    
         animation.Play("animationJetOff"); 
         WaitForSeconds(0.25);
         if(jetAudio){
             audio.Pause();
         }
     }
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
1
Best Answer

Answer by aldonaletto · Sep 08, 2012 at 05:21 AM

I would do the following: set the fields Play On Awake and Loop in the AudioSource, so that the jet sound would be playing continuously, and control only its volume (the sound should be loopable, of course). I would also change a little the logic to ease detecting when the jet is turning on and off, like this:

var fadeInTime: float = 0.25; var fadeOutTime: float = 2.5;

private var jetOn = false; private var vol: float = 0;

function Update(){ var oldJet = jetOn; // save last jetOn state to detect changes jetOn = Input.GetButtonDown("Horizontal") || Input.GetButtonDown("Vertical"); if (jetOn != oldJet){ // if jetOn changed... if (jetOn){ // start the suitable animation animation.Play("animationJetOn"); } else { animation.Play("animationJetOff"); } } if (jetAudio){ if (jetOn){ // fade in/out the sound according to jetOn: vol += Time.deltaTime / fadeInTime; } else { vol -= Time.deltaTime / fadeOutTime; } vol = Mathf.Clamp(vol, 0, 1); // keep it in the 0..1 range audio.volume = vol; // update the actual audio volume } }

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 Android Matt · Sep 08, 2012 at 10:25 PM 0
Share

Thanks Aldo, that helped a lot!

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

9 People are following this question.

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

Related Questions

Anima 2D: change Sprite while a animation? 0 Answers

Trying to play other objects' sound and animations from Raycast hit 1 Answer

Footstep sounds when walking 7 Answers

Connecting split and random animations to correct audio 1 Answer

Play Audio in Animation Window 0 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