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 Ilkzz · Jun 03, 2014 at 11:56 PM · c#sound

Play 2 audio's one after another

Hi,

I can't seem to figure out why 2 sounds do not play one after another. Only the first one plays and the second does not. I have set each of my sounds on a game object. The bit of my code is as follows:

 if (hasPlayed == false)
         {
             DieSound.Play();
             hasPlayed = true;
 
             if (hasPlayed == true)
             {
                 FalldownSound.Play();
             }
         }

Where am I going wrong?

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 meat5000 ♦ · Jun 04, 2014 at 12:07 AM 0
Share

Load them in to the AudioClip, then play the clip.

One after another.

avatar image Ilkzz · Jun 04, 2014 at 12:18 AM 0
Share

Im not quite sure what you mean by loading them in to the AudioClip

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by screenname_taken · Jun 07, 2014 at 10:38 PM

Take them out of update and into their own function.

Make an array of two audio clips, load the first one and play it, and right after the call to play it use "yield WaitForSeconds(audio.clip.length);" and right after that load the second clip and play that.

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

Answer by Tanshaydar · Jun 04, 2014 at 12:39 AM

You can't play to sounds at once at one AudioSource. You need to play then one after another, or play them at different sources. If you want to do former, here it is:

in Awake

 bool hasPlayed_1 = false;
 bool hasPlayed_2 = false;

in Update

 if ( !hasPlayed_1) {
      DieSound.Play();
      hasPlayed_1 = true;
 }
 if ( hasPlayed_1 && !hasPlayed_2 && !audio.isPlaying) {
       FalldownSound.Play();
       hasPlayed_2 = true;
 }


If you have two different audio sources, then well, you can just get rid of the audio.isPlaying part and it will do the trick.

Comment
Add comment · Show 2 · 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 Ilkzz · Jun 07, 2014 at 10:00 PM 0
Share

This seems to play the sounds at the same time, or its so quick it sounds like they do

avatar image Tanshaydar · Jul 14, 2014 at 01:33 PM 0
Share

Updated the function, sorry, I forgot to add a variable to if clause.

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

24 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Photon help for a noob! 0 Answers

Proper walk sound / audio play script c# 1 Answer

How to make my machinegun echo? 3 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