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
0
Question by Bunin · Oct 23, 2013 at 01:59 PM · audioaudiosourcemultiplefadeout

Multiple audio samples on one object.

I need your help. I'm trying to learn C#. I want to do that on a one single object were three audio samples and when I click on object with mouse button - sounds were played back in sequence. First click = sound 1, second click = sound 2, third click = sound 3...and again first click = sound 1.

I'm trying to make this so:

 public AudioClip sound1;
 public AudioClip sound2;
 public AudioClip sound3;
 void OnMouseDown ()
 {
 audio.PlayOneShot(sound1);
 }

But I don't understand how to play another two audio in sequence. I also need that when I released the mouse button the sound faded using 1 second audio fade-out. How can I make this fadeout?

Help me please.

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
0

Answer by save · Oct 23, 2013 at 02:17 PM

Put the AudioClip's in a built-in array and use a pointer which you increment and reset when it has reached the length of the AudioClip array. Make use of coroutines to play, fade in and fade out the sound.

Read this article about arrays and how you can work with them. What I usually do when I have a pointer in an array is to increment it with a remainder to reset it to zero when exceeded the length of the array. For instance:

 audioClipArray[i].Play();
 i++; i=i%audioClipArray.Length;

Next step is volume, an AudioSource can only play one clip at a time as far as I know, so use two AudioSources. During the length of the audio you fade in and fade out the sound, for instance have a look at Duck's answer on this issue to get you started. A coroutine will make excellent use in this case.

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 Bunin · Oct 24, 2013 at 05:14 AM 0
Share

Thank you! I'll try it.

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

14 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

Related Questions

Buzzing Audio 1 Answer

Multiple audioSources on same gameObject? 1 Answer

How can I play multiple audioclips from the same object? 2 Answers

How to play sound after another with one button (and after full round continue from where the clip stopped)? 0 Answers

Audio won't fade out. 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