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 emirayranci18 · Feb 19, 2021 at 05:52 PM · audioscript.audiosourceaudioclip

Only one audio active. Others do not activate

I'm trying to make a voice dialogue. They have to speak in turn but only one audio active, others do not activate.How can i activate together all of them

 void OnTriggerStay(Collider col)
     {
         if (col.gameObject.name == "fps" && gor==1)
         {
             
             audio.clip = b1;
             audio.Play();
             Text1.SetActive(true);
 
             if (Input.GetKeyDown(KeyCode.F))
             {
                 gor = 2;
                 Text1.SetActive(false);
                 if (sira == 0)
                 {
                     audio.clip = b2;
                     audio.Play();
                     sira = 1;
 
                     if (!audio.isPlaying)
                     {
                         audio.clip = b3;
                         audio.Play();
                         sira = 2;
 
                         if (!audio.isPlaying)
                         {
                             audio.clip = b4;
                             audio.Play();
                             sira = 3;
 
 
                             if (!audio.isPlaying)
                             {
                                 audio.clip = b5;
                                 audio.Play();
                                 sira = 4;
 
 
                                 if (!audio.isPlaying)
                                 {
                                     audio.clip = b6;
                                     audio.Play();
                                     sira = 5;
 
 
                                     if (!audio.isPlaying)
                                     {
                                         audio.clip = b7;
                                         audio.Play();
                                     }
                                 }
                             }
                         }
                     }
                 }
 
             }
         }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by MUG806 · Feb 19, 2021 at 07:15 PM

Is the idea to play each clip in sequence when the last one finishes? You have the right sort of idea, your if-statements are just set up wrong. You want something more like this:

 if (!audio.isPlaying) {
             if(audio.clip == b1) {
                 audio.clip = b2;
                 audio.Play();
             }
             else if(audio.clip == b2) {
                 audio.clip = b3;
                 audio.Play();
             } //.... etc ...
 }

The above code should work fine, just takes a while to write a bit for every single audio clip. If you want a better solution you can try using an array and a for loop. If you need an example of that let me know and I can write something up for you

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 emirayranci18 · Feb 19, 2021 at 11:23 PM

@MUG806 Thanks for your help but I don't understand how to use the array and for loop Can you give an example?

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 MUG806 · Feb 20, 2021 at 11:42 PM 0
Share

I was actually mistaken and you dont even need a for loop:

 public AudioClip[] clips //Drag all your sound clips into this in the inspector.
 int nextClip= 0;
 void Update(){
   if (!audio.isPlaying){
     if(nextClip < clips.length){
          audio.clip = clips[nextClip];
          audio.Play();
          nextClip++;
     }
   }
 }

This works by storing the clips in an array, and storing a number for which clip we need to play next. Each time the audioSource isn't playing, we check if we got to the end of all the clips, and if not, we play the clip at the "nextClip" number we stored, and then add 1 to the stored number so that next time we play the next clip.

avatar image emirayranci18 MUG806 · Feb 21, 2021 at 11:39 AM 0
Share

@MUG806 Thank you so much. It worked.

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

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

Related Questions

Problem with playing sound on Trigger-Enter 2 Answers

How to get decibel's value of game's sound? 0 Answers

Glitched Music 0 Answers

Play audio at consistent volume 2 Answers

AudioSource won't play 2 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