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 Trezla · Aug 28, 2012 at 02:33 PM · gameobjectaudiosourcewaitforsecondshow tomute

How to Mute / Unmute audio after WaitForSeconds()

I want to mute another AudioSource on another gameObject while I play a soundEffect and once that soundEffect has finished playing the music will unmute. How would I script that?

Thanks for any help it will be really appreciated thanks.

Comment
Add comment · Show 1
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 AlucardJay · Aug 28, 2012 at 05:30 PM 0
Share

Here's something I did with muting, but I cannot help with C# and yield.

http://answers.unity3d.com/questions/233420/musical-game-mute-and-unmute-trigger-soundsource.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Seth-Bergman · Aug 28, 2012 at 02:55 PM

you can pause it or mute it: AudioSource.Pause & AudioSource.mute:

http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.Pause.html

http://docs.unity3d.com/Documentation/ScriptReference/AudioSource-mute.html

EDIT:

here's an example:

(javascript)

     var otherObject : GameObject;
     
     function Start(){
     otherObject = GameObject.Find("NameOfObject");
     }
     
     function PlaySound(){
     otherObject.audio.mute = true;
     audio.Play();
     while(audio.isPlaying){
     yield;
     }
     otherObject.audio.mute = false;
     }

I think this should do it

(edit again) Oops, looks like you're using C#, so like this I think:

     private GameObject otherObject;
     
     void Start(){
     otherObject = GameObject.Find("NameOfObject");
     }
     
     IEnumerator PlaySound(){
     otherObject.audio.mute = true;
     audio.Play();
     while(audio.isPlaying){
     yield return 0;
     }
     otherObject.audio.mute = false;
     }

my C# is rusty, but I think this should work

Comment
Add comment · Show 4 · 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 Trezla · Aug 28, 2012 at 04:43 PM 0
Share

I know how to do that but how would I unmute another audiosource on another gameObject after the sound effect has finished playing using the code 'yield WaitForSeconds(soundEffect.length)'.

I'm not too sure where to put 'yield' i'm currently putting it in the Void Update() but i know that it will not work in there so where would I put it?

Thanks.

avatar image Seth-Bergman · Aug 28, 2012 at 05:51 PM 0
Share

added an example above.. this would be on the object playing the sound effect. Then all that's left is to call PlaySound() at the appropriate time..

avatar image Trezla · Aug 28, 2012 at 09:16 PM 0
Share

Thanks for the quick reply but how does this work i can't seem to make this work?

Thanks anyway.

avatar image Trezla · Aug 28, 2012 at 09:50 PM 0
Share

I have solve my question but thank you very much for helping me much appreciated. this is what I used to solve my issue:

// Javascript

function $$anonymous$$uteSound(){

 Playlist1.mute = true;

 while(audio.isPlaying){

 yield WaitForSeconds(audio.clip.length);

     Playlist1.audio.mute = false;

 Playlist1.mute = false;

 }

I had to use javascript because I know how to use the Yield function in that language but not so much in C#.

Thank You anyway. :D

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I play multiple AudioSources from one gameobject? 8 Answers

AudioSources don't play when setting Time.timescale to 0 3 Answers

Continuous AudioSource in DontDestroyOnLoad 1 Answer

DontDestroyOnLoad problem 1 Answer

AudioSources don't play when setting Time.timescale = 0 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