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 /
This question was closed Feb 22, 2014 at 12:10 AM by unimechanic for the following reason:

Duplicate Question

avatar image
-1
Question by PaxStyle · Feb 18, 2014 at 09:25 PM · audiofade

Fade Audio

Hi guys, How can I do for make a fade at "Motore2" when i press A?

Sorry for my bad english!

 using UnityEngine;
 using System.Collections;
  
 public class Audio : MonoBehaviour
 {
     public AudioClip Motore1;
     public AudioClip Motore2;
     float soundPitch = 0;
     float maxSpeed = 2;
     float minSpeed = 0.2f;
  
  
  
     void Start()
     {
        if (!audio.playOnAwake) audio.Play();
     }
  
  
     // Update is called once per frame
     void Update () 
     {
        soundPitch = Mathf.Clamp(soundPitch, minSpeed, maxSpeed);
  
  
        if (Input.GetKey(KeyCode.A)) 
        {
          audio.clip = Motore1;
          soundPitch+= 0.09f;
          audio.pitch = (soundPitch);
  
        }
  
  
  
        if (Input.GetKey (KeyCode.D)) 
        {
          audio.clip = Motore2;
          soundPitch+= 0.09f;
          audio.pitch = (soundPitch);
        }
  
  
        if (Input.GetKey (KeyCode.S)) 
        {
          soundPitch-= 0.09f;
          audio.pitch = (soundPitch);
        }
  
     }
  
  
 }
Comment
Add comment · Show 5
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 POLYGAMe · Feb 18, 2014 at 09:42 PM 1
Share

You probably want to handle setting the clips separately, as in that code, it will reset the audio clip every frame if the key is held down.

avatar image AndyMartin458 · Feb 18, 2014 at 10:04 PM 1
Share

Changing the pitch doesn't really seem like a fade to me.

avatar image JeffreyD · Feb 18, 2014 at 10:12 PM 0
Share

This is a duplicate question. http://answers.unity3d.com/questions/639589/reduce-audio-volume.html

http://answers.unity3d.com/questions/640426/reduce-audioclip-when-a-key-is-pressed.html

I given you the starter code to handle what you are looking for along with the pseudo code you created. If you look at the code I gave you closely you will see that all you need to do is duplicate the case I gave you and change a few plus to $$anonymous$$us signs, then change the name of the vars for motor2.

I'm not sure what else to do to help other than write all of it out for you.

avatar image POLYGAMe · Feb 18, 2014 at 10:29 PM 0
Share

HAHAHA! @Andy$$anonymous$$artin458 - good point! $$anonymous$$ight wanna be adjusting the volume ins$$anonymous$$d. LOL.

avatar image AndyMartin458 · Feb 18, 2014 at 10:49 PM 0
Share

@POLYGA$$anonymous$$e Indeed! I also agree with you about setting the clip each update frame. Not the right approach.

1 Reply

  • Sort: 
avatar image
0

Answer by unimechanic · Feb 22, 2014 at 12:09 AM

Duplicate Question:

http://answers.unity3d.com/questions/639589/reduce-audio-volume.html

http://answers.unity3d.com/questions/640426/reduce-audioclip-when-a-key-is-pressed.html

[Adding this answer to remove it from the Unanswered list.]

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

Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image avatar image

Related Questions

Why do AudioMixerSnapshots not crossfade properly when transitioning? 0 Answers

Activate sound without Pro filters 0 Answers

Fading out before load script not functioning correctly? 2 Answers

Fading Audio in/out with object creation 1 Answer

Smooth GUI and Audio Volume Fades 5 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