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 PaxStyle · Apr 19, 2014 at 03:50 PM · audiostop

Stop AudioClips by script (c#)

How can i do to stop the audioclips that i've declared in a script? for example:

 public AudioClip Audio1;
 public AudioClip Audio2;
 public AudioClip Audio3;
 
 
 void update()..
 if (Input.GetKeyDown (KeyCode.N)) {
 audio1.volume = 0.0;
 audio2.volume = 0.0,
 audio3.volume = 0.0;
 }

Thank you in advance

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
Best Answer

Answer by chufraise · Apr 19, 2014 at 04:03 PM

Use AudioSource instead, and assign your AudioClip to AudioSource.clip.

Good luck!

Comment
Add comment · Show 10 · 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 PaxStyle · Apr 19, 2014 at 05:24 PM 0
Share

ok i make so, but unity editor gives me this error: Literal of type double cannot be implicitly converted to type float'. Add suffix f' to create a literal of this type

  public class Scream : $$anonymous$$onoBehaviour {
     
         public AudioSource Audio1;
         public AudioSource Audio2;
         public AudioSource Audio3;
         public AudioSource Audio4;
         public AudioSource Audio5;
         public AudioSource Audio6;
     
         
         // Update is called once per frame
         void Update () {
         
         if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.N)) {
     
         Audio1.volume = 0.0;
         Audio2.volume = 0.0;
         Audio3.volume = 0.0;
         Audio4.volume = 0.0;
         Audio5.volume = 0.0;
         Audio6.volume = 0.0;
     
         }
 .
 .
 .
 .
 .
 

avatar image chufraise · Apr 19, 2014 at 06:03 PM 0
Share

Yes, you should add a float suffix. Like:

 Audio1.volume = 0.0f; 

ins$$anonymous$$d of

 Audio1.volume = 0.0;
avatar image PaxStyle · Apr 19, 2014 at 06:11 PM 0
Share

Ah ok, but there are other problems with the other parts of the script, now i show you the full script, the message error now is: The best overloaded method match for `UnityEngine.AudioSource.PlayOneShot(UnityEngine.AudioClip)' has some invalid arguments what does it mean?

 public AudioSource Audio1;
     public AudioSource Audio2;
     public AudioSource Audio3;
     public AudioSource Audio4;
     public AudioSource Audio5;
     public AudioSource Audio6;
 
     
     // Update is called once per frame
     void Update () {
     
     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.N)) {
 
     Audio1.volume = 0.0f;
     Audio2.volume = 0.0f;
     Audio3.volume = 0.0f;
     Audio4.volume = 0.0f;
     Audio5.volume = 0.0f;
     Audio6.volume = 0.0f;
 
     }
 
 
     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.A)) {
     StartCoroutine (Wait$$anonymous$$ethod ());
     } 
     else if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.D)) {
     StartCoroutine (Wait$$anonymous$$ethod2 ());
     }
     }
     
 
 
     IEnumerator Wait$$anonymous$$ethod(){
     yield return new WaitForSeconds(2f);
     audio.PlayOneShot(Audio1);
     audio.PlayOneShot(Audio2);
     audio.PlayOneShot(Audio3);
     
     audio.Play();
     }
 
 
     IEnumerator Wait$$anonymous$$ethod2(){
     yield return new WaitForSeconds(2f);
     audio.PlayOneShot(Audio4);
     audio.PlayOneShot(Audio5);
     audio.PlayOneShot(Audio6);
         
     audio.Play();
     }
 
 }
 
avatar image chufraise · Apr 21, 2014 at 07:28 PM 0
Share

Ah, ok. You mixed things up a bit. Either you declare AudioClip variables as you initially did. Then to change the volume you just have to do it on the AudioSource component, like: audio.volume = 1f; Then to play them you type: audio.PlayOneShot(clip);

The other way is to declare AudioSource variables, and set their volumes individually, like Audio1.volume = 1f; Then to play them you type: Audio1.Play();

Hope it helps!

avatar image PaxStyle · Apr 21, 2014 at 08:25 PM 0
Share

mhmh i don't understand very well, so i have to declare the audioclip at the start as i already did, and then in void update set the "audio.volume = 0f;"?

Show more comments

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

21 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

Related Questions

Activate audio when the key is pressed. 1 Answer

Keeping audio between all but one scene? 1 Answer

my audio is not looping even when it is set to loop 5 Answers

How can you stop all other audio sources from playing and then start a new audio source? 3 Answers

Stop sound on input.getkeyup 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