Question by
bonez9oh5 · Mar 24, 2017 at 07:10 PM ·
c#scene-switchingaudio listener
How do i switch a boolean in my GameManager with a toggle in CanvasManager through reference in C#?
What im trying to do is use a UI toggle on my options screen to mute my audio.
if (muted == false)
{
AudioListener.pause = false;
Debug.Log("game is unmuted");
}
else
{
AudioListener.pause = true;
Debug.Log("game is muted");
}
this bool works to mute, located in my GameManager in order to carry the code across my various scenes.
two options i have, using what i have
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class CanvasManager : MonoBehaviour {
public Toggle Mute;
GameManager gm;
// Use this for initialization
void Start () {
// find and assign GameManager script to variables (buttons)
gm = GameObject.Find("GameManager").GetComponent<GameManager>();
}
void Update () {
if (SceneManager.GetActiveScene().name == "Options")
{
if (Mute)
{
Mute.toggleTransition.(gm.Mute);
}
}
}
I can either use the toggleTransition to call this function
public void Mute()
{
if (muted == false)
{
muted = true;
}
else
{
muted = false;
}
}
from the GameManager or i can use an "if" statement with "isOn/!isOn" to change the bool "muted" in the GameManager. Either code would help.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612113858im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Remember UI setting from Previous Scene When Return to Scene 0 Answers
Need a Script for Changing Scenes after pressing E to open locked door once a key has been found. 0 Answers
How to keep selected player active and all others inactive when new scene loaded 3 Answers