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 PushpaK · Jan 31, 2013 at 11:56 AM · soundmusic

Disable all sounds in Game except background music

I have sounds attached to various game objects in my game and background music to one game object. I want to disable those sounds(like collision sounds,cry sound,shouting sound) but want to play background music continuous. Anybody knows how to do it?

I tried to deactivate camera listener but it mutes all sounds with music.

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

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by louisdeb · Jan 31, 2013 at 01:43 PM

Before each of your statements to play sounds put an if statement checking for a global bool (eg public bool playSound;) which you just change based on whether you want the sounds playing. Don't put the if statement in front of the background music or if you want to disable that as well at any point then use a different bool variable (eg backgroundMusicPlay)

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 Punkjim420 · Jan 31, 2013 at 12:27 PM

in javascript,

if you want, one method(maybe not the best) would be to add an if statement in all of the objects you want to mute.

 function Update() {
      if(yourMainScriptsName.muteNow)) {
             audio.mute = true;
      }
      else{
             audio.mute = false;
      } 

but you have to set the boolean "muteNow" in your mainScriptName to static

 static var muteNow : boolean = (trueorfalseyourchoice);

minus the ( ) around your choice.

Comment
Add comment · Show 1 · 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 PushpaK · Feb 01, 2013 at 06:14 AM 0
Share

If I use playerPrefs variables will it harm working on mobile devices? And using it I can save changes permanently.

avatar image
0

Answer by the_pheNom · Jun 07, 2014 at 12:06 PM

i have similar function

i am able to disable button sound perfectly, while having my bg music playing

however, how do i do the opposite. have my button sounds play while i disable the bg music

and is there a way to stop an audio file tht is currently playing ( not by reducing the volume of audiolistener, cause i need other sounds like button sounds to keep going)

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 screenname_taken · Jun 07, 2014 at 12:20 PM

The way i do it is, i have two floats saved in player prefs. one for music volume and one for sound effects volume. Whenever i trigger an sfx to play, i first check the volume and then play the clip with that volume. So i just have to change the float in player prefs to quiet one or the other or both.

Comment
Add comment · Show 3 · 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 the_pheNom · Jun 09, 2014 at 11:57 AM 0
Share

hmm.... the problem im facing is

my scene starts and a bg music plays... all buttons have sounds to it wen clicked or tapped

if i mute sounds... the bg music play -> which is wat is i want

but wen i mute music... i need to stop the bg music and enable the button sounds... i could use ur suggestion and have playerprefs for sound n music volume

but once the music starts playing i cant seem to edit or stop tht music. it plays fully ... i need a cmd to stop the bg music immediatly... NOT LOWER THE VOLU$$anonymous$$E/DISABLE AUDIOLISTENER

hope i made sense!! :/

avatar image screenname_taken · Jun 09, 2014 at 12:09 PM 0
Share

Just use audio.Stop(); on the component that has the sound you want to stop playing. And i wasn't disabling the audio listener.

avatar image the_pheNom · Jun 11, 2014 at 02:16 PM 0
Share

ty :) was making a stupid error and complicating everything in my head... ur comment helped.. TY :D

avatar image
0

Answer by MrWy07 · Dec 22, 2021 at 12:36 PM

I know I'm late, but if someone's looking for a solution here's mine: Loop through all AudioSources and disable them if there are different of your background music.

 foreach(AudioSource i in GameObject.FindObjectsOfType<AudioSource>()) {
             if(i != music) {
                 i.volume = i.volume > 0 ? 0 : 1; // or just i.voume = 0 or something    
             }
         }


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

14 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

Related Questions

Trigger Start of Sound 1 Answer

Sound effect doesn't play correctly 1 Answer

Sound gets loud in while playing game? 1 Answer

Can I use SoundCloud music for my game or showcase ? 0 Answers

How to apply sound to shape keys in animation. 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