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 Cyborg_Sam · Nov 11, 2017 at 07:18 PM · c# tutorialmute

C# Mute Button across scenes Problem

Hi, I have been trying to solve this problem for a few days now...No joy.

I have followed this tutorial to get Background that changes across my levels using an AudioManager [MEDIA=youtube]uNX5NrHvfWY|start=451[/MEDIA]

AudioManager

[code=CSharp]using System.Collections; using System.Collections.Generic; using UnityEngine;

public class AudioManager : MonoBehaviour {

     public AudioSource BackGroundMusic;

 // Use this for initialization
 void Start () {

             DontDestroyOnLoad (gameObject);

             if (FindObjectsOfType<AudioManager> ().Length > 1)
             {
                     Destroy (gameObject);
             }
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }

     public void ChangeBGM (AudioClip music)
     {
             if (BackGroundMusic.clip.name == music.name)
                     return;
   
             BackGroundMusic.Stop ();
             BackGroundMusic.clip = music;
             BackGroundMusic.Play ();
             BackGroundMusic.loop = true;
     }

} [/code]

AudioManagerCheck

[code=CSharp]using System.Collections; using System.Collections.Generic; using UnityEngine;

public class AudioManagerCheck : MonoBehaviour {

     public GameObject audioMan;

 // Use this for initialization
 void Start () {

             if (FindObjectOfType<AudioManager> ())
                     return;
             else
                     Instantiate (audioMan, transform.position, transform.rotation);
 
 }
 
 // Update is called once per frame
 void Update () {

 
 
 }

} [/code]

SwitchMusicOnLoad

[code=CSharp]using System.Collections; using System.Collections.Generic; using UnityEngine;

public class SwitchMusicOnLoad : MonoBehaviour {

     public AudioClip newTrack;

     private  AudioManager TheAudioManager;
 

     // Use this for initialization
     void Start () {

             TheAudioManager = FindObjectOfType<AudioManager> ();
      

             if(newTrack != null)
             TheAudioManager.ChangeBGM (newTrack);

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

} [/code]

And now I have followed this tutorial [MEDIA=youtube]ABqmWhD5Ny8[/MEDIA]

MuteButton

[code=CSharp]using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor;

public class MuteButton : MonoBehaviour {

 public GameObject audioOnIcon;
 public GameObject audioOffIcon;

 // Use this for initialization
 void Start () {
     SetSoundState ();
  



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

 public void ToggleSound()
 {
     if (PlayerPrefs.GetInt ("Muted", 0) == 0) {
         PlayerPrefs.SetInt ("Muted", 1);
     }
     else
     {

         PlayerPrefs.SetInt ("Muted", 0);
     }

     SetSoundState ();
 }

 private void SetSoundState()
 {
     if (PlayerPrefs.GetInt ("Muted", 0) == 0)
     {
   
         AudioListener.volume = 1;
         audioOnIcon.SetActive (true);
         audioOffIcon.SetActive (false);
     }
             else
     {
   
         AudioListener.volume = 0;
         audioOnIcon.SetActive (false);
         audioOffIcon.SetActive (true);
     }
 }

} [/code]

so I can save the toggle of a mute button.

The problem is, I need to access the AudioSource on the AudioManager/AudioManager clone via the Mute Button and have it mute the AudioSource and not the AudioListener, because the background music is controlled by the AudioManager and I have other sounds that I would like to keep playing when mute is toggled on).

I hope I have given enough detail for one of you amazing C# experts to help me solve. Thank you,

Sam

This is a test the Go_1 sound is the sfx sound that should still be playing after mute is toggled on or off.

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

0 Replies

· Add your reply
  • Sort: 

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

72 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

Related Questions

PlayerPrefs for Mute/Unmute button 1 Answer

Sound volume on different colisions 1 Answer

C# to find a Object in a direction on a 2D map 0 Answers

convert gradient in to color keys 1 Answer

How to rotate player controller properly 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