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 /
avatar image
0
Question by sachinbirajdar · Nov 15, 2017 at 12:41 PM · audiotoggle buttonmute

How to mute/unmute audio from a single scene while its being played in multiple scenes?

Hello, I have an "Toggle" to mute or unmute audio in my menu scene.It works fine, but when I go to Game scene and come back to menu scene the Toggle stops working.I have a script attached to the gameobject which allows the audio to play through all scenes without starting from beginning.And the same gameobject's values are used to Toggle. Please help me solve this issue. The script is....

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class MusicSc : MonoBehaviour {

 // Use this for initialization
 void Start () {

 }

 //Play Global
 private static MusicSc instance = null;
 public static MusicSc Instance
 {
     get { return instance; }
 }

 void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
         return;
     }
     else
     {
         instance = this;
     }

     DontDestroyOnLoad(this.gameObject);
 }
 //Play Gobal End

 // Update is called once per frame
 void Update () {

 }

}

Comment
Add comment · Show 4
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 EDevJogos · Nov 15, 2017 at 05:08 PM 0
Share

@sachinbirajdar Is the toggle part of this same singleton gameObject that you posted above? and how the toggle is failing? is it showing the wrong value? is it not interactable anymore?

avatar image sachinbirajdar EDevJogos · Nov 16, 2017 at 06:28 AM 0
Share

Its not intractable anymore.....

avatar image Przemo0c · Nov 16, 2017 at 08:32 AM 1
Share

I'm not sure if that would be a problem but the solution should look sth like this : This would be your $$anonymous$$usic Player script, that you attach to a GameObject with AudioSource Component probably at the first scene the music is supposed to start playing and the rest of the scenes where the same music should be played : public class $$anonymous$$usicPlayer : $$anonymous$$onoBehaviour {

     static $$anonymous$$usicPlayer instance = null;
         void Awake () {
          //print("$$anonymous$$usic Plyer awake "+ GetInstanceID());
          //print("$$anonymous$$usic player Start "+ GetInstanceID());
     
         if (instance != null)
           {
             Destroy(gameObject);
           } else
           {
             instance = this;
             DontDestroyOnLoad(transform.root.gameObject);
           }
         }
         // Use this for initialization
         void Start(){
     
         }

The script creates one $$anonymous$$usic Player and if there is another $$anonymous$$usic Player in the scene it destroys it, which means that you will have constant $$anonymous$$usic Playing without starting from beginning every level.

If you want to disable it, just try doing sth like this to turn this music player off:

Your Function(){

 GetComponent<$$anonymous$$usicPlayer>().enabled = false;

} ;) hope it helps

avatar image sachinbirajdar Przemo0c · Nov 20, 2017 at 05:54 PM 0
Share

Yeah....it helped me...great....thanks...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NorthStar79 · Nov 21, 2017 at 08:04 AM

you should use "audio mixer" for ultimate control of your audio.

destroying audio source object or disabling audio source component does not work because they will return their original state when scene re-loaded. but if you set audio mixers volume to "0" it will stay that way.

here a good youtube video tutorial for "audio mixer"

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

90 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

Related Questions

Mute Unity Ads in code? 2 Answers

AudioMixer Mute Button 1 Answer

All Unity-related audio stopped working 2 Answers

[URGENT] WebGL export completely different from editor playtesting. [C#] 1 Answer

Mute/Unmute not working with new sounds 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