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 Feretro · May 07, 2018 at 08:13 PM · audiosourceaudioclipsounds

Playing and Pausing multiple audio clips

Hello! I am pretty new at unity and c# and struggling on how to use two (or more) separate audio clips on my GameObject.

I have a sort of "footsteps on grass" sound that is playing when:

" float orizzontale = Input.GetAxis("Horizontal");" is > or < than 0 and stop when it's 0.

Now footsteps in the grass is working fine: It stops and it comes again ... but when I jump I can't hear sound.

I think the reason is that i put AUDIOSOURCE in pause or stop. How can I pause just a clip and not the whole Audiosource?

 void SuoniPorco(float orizzontale) {
     
             if (orizzontale < 0 && !suoni.isPlaying && !porcoInVolo || orizzontale > 0 && !suoni.isPlaying && !porcoInVolo) **//If my player is moving and is not jumping, then ...**
     
     {
     
                 suoni.PlayOneShot(cammina); **// Play Sound Clip Until ....**
     
             }
           
     
             if (Mathf.Abs(orizzontale) < 0.001 || porcoInVolo) **//Player is not moving or he's jumping** 
             {
     
                 suoni.pause();  **//If so ... PAUSE this clip**
     
             }
     
     **// IF player Jumps ... then PLAY a JUMP sound**
     
             if (porcoSalta) {
     
     
                 suoni.PlayOneShot(salto);
                 porcoSalta = false;
     
             }
     
          }
 
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 Feretro · May 07, 2018 at 09:00 PM

I've found a solution, but I don't know IF this is the right way to do:

I dragged my TWO (by now!) sounds into the Hierarchy and then, in the code I created a:

 public AudioSource[] sounds;

I DID NOT assigned that "sounds" variable to the AudioSource Component (why? I had an error!) ... I did not code this line:

 sounds = GetComponent<AudioSource>(); // I do Not have this line in my code

Then, back in the UnityEditor, I set the array size to 2 and then dragged two AudioClips from hierarchy.

and so, I can access to sounds separately:

         sounds[0].Play();
         sounds[1].Play();

or

         sounds[0].Pause();
         sounds[1].Pause();

I don't know if this is the right way to ... probably not ... but now my two sounds work together well! :-)

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

139 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

Related Questions

How to Send Audio Clip Via Facebook Messenger ? 0 Answers

Playing many AudioSources 1 Answer

I get: 'UnassignedReferenceException' when trying to play a sound clip though a sound source, yet i am assigning it. HELP?! 0 Answers

Second AudioClip won't play 0 Answers

My sound effect is not playing 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