Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by linelade · Aug 24, 2017 at 03:23 PM · audioscript.

fading in and out sounds

hey everyone,

So i have this script where i play 2 sounds after each other on entercollider.

however, i want the clips to be faded in and out when entering and exiting the collider how do I go about that?

this is my code untill now

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class fadeforcouple : MonoBehaviour {

 public AudioSource source;
 public AudioSource source2;
 public AudioClip goaway;
 public AudioClip shoo;

 private IEnumerator PlaySounds ()
     {
         // Play the first sound

     AudioSource.PlayClipAtPoint(goaway, transform.position);

         //Then wait 3 seconds and play the other

         yield return new WaitForSeconds(7);

     AudioSource.PlayClipAtPoint(shoo, transform.position);
     }



 private void OnTriggerEnter ()
 {
     StartCoroutine(PlaySounds());
 }

 private void OnTriggerExit ()
 {
     StopCoroutine(PlaySounds());

 }

}

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 FortisVenaliter · Aug 24, 2017 at 04:22 PM 0
Share

What have you tried so far?

avatar image linelade · Aug 24, 2017 at 04:36 PM 0
Share

@FortisVenaliter

I tried from a youtube tutorial like

IEnumerator fadesound() while(source.volume > 0.01f) { source.volume =- Time.deltatime/ 1.0f; yield return null;

{ source.volume = 0; source.stop ();

And i stumble upon quite a lot of posts related to this but im not that good in program$$anonymous$$g yet and so i dont understand how to apply it to my own code...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by linelade · Aug 27, 2017 at 11:25 AM

something like this, but im quite noob and dont really get what to call in the trigger enter and exit?

 public AudioSource source;
 public AudioSource source2;
 public AudioClip goaway;
 public AudioClip shoo;


 private IEnumerator PlaySounds ()
     {

     AudioSource.PlayClipAtPoint(goaway, transform.position);

         yield return new WaitForSeconds(7);

     AudioSource.PlayClipAtPoint(shoo, transform.position);
     }


 IEnumerator FadeAudio(bool fadeIn, float fadeSeconds = 1)
 {
     for (float i = 0; i < 1; i += Time.deltaTime / fadeSeconds)
     {
         AudioSource.volume = fadeIn ? i : 1 - i;

         yield return null;
     }
 }



 private void OnTriggerEnter ()
 {
     
     StartCoroutine(PlaySounds());


 }

 IEnumerator OnTriggerExit ()

 {
     StopCoroutine(PlaySounds());
     yield break;
 


         }
     }
 

     
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

84 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 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 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 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

How do you add audio to Audio Clip (via scripting) during gameplay? 1 Answer

Audio play when enter trigger 1 Answer

Audio on keydown Won't stop 1 Answer

Trying to make a splitscreen game, having issues with the AudioSource and distance between objects. 0 Answers

Recording Players voice in Unity using VR buttons. 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