If statements with AudioListener C# ?
I have a mute script, and a pause script (overlay kind of pause). Basically I want it so if you have the game normal as in not muted, pressing "p" (to pause) mutes the game (sets AudioListener.volume to 0) and then on un pause (P again), it sets the volume to 1. HOWEVER, IF the game was muted before, do nothing (as in keep the game muted throughout the pause and unpause).
I need something like this: if AudioListener = 0 then do nothing, else, make AudioListener 0 until p is pressed again.
(NO IDEA OF THESE MATTER BUT HERE ARE MY MUTE AND PAUSE SCRIPTS) (c#): Mute:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MuteMusic : MonoBehaviour
{
public GameObject Music;
public bool mutee;
void Start()
{
AudioListener.volume = 1;
}
void Update()
{
Mute();
}
void Mute()
{
if (Input.GetKeyDown("m"))
{
mutee = !mutee;
if (mutee)
{
AudioListener.volume = 0;
}
else
{
AudioListener.volume = 1;
}
}
}
}
PAUSE SCRIPT: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.Characters.FirstPerson;
public class PauseGame : MonoBehaviour
{
private FirstPersonController myControl;
public GameObject m9;
public GameObject PauseThing;
private bool onoff;
private void Awake()
{
myControl = GameObject.Find("FPSController").GetComponent<FirstPersonController>();
}
void Start()
{
PauseThing.SetActive(false);
}
void Update()
{
PauseTheGame();
}
void PauseTheGame()
{
if (Input.GetKeyDown("p"))
{
onoff = !onoff;
if (onoff)
{
Time.timeScale = 0;
myControl.m_MouseLook.XSensitivity = 0;
myControl.m_MouseLook.YSensitivity = 0;
m9.SetActive(false);
AudioListener.volume = 0;
PauseThing.SetActive(true);
}
else
{
Time.timeScale = 1;
myControl.m_MouseLook.XSensitivity = 2;
myControl.m_MouseLook.YSensitivity = 2;
m9.SetActive(true);
AudioListener.volume = 1;
PauseThing.SetActive(false);
}
}
if (Input.GetKey(KeyCode.Escape))
{
Time.timeScale = 1;
myControl.m_MouseLook.XSensitivity = 2;
myControl.m_MouseLook.YSensitivity = 2;
m9.SetActive(true);
AudioListener.volume = 1;
PauseThing.SetActive(false);
}
}
}
Thank you!
Your answer
Follow this Question
Related Questions
Cursor Lock Code w/ if, else if, and else Statement Errors 1 Answer
If statement on float number not working 0 Answers
Enable/Disable AudioListener c# 2 Answers
How do I call an if and else statement on a Countdown timer Script 0 Answers
Looking to overlook arguments based on parameters elsewhere in the code. (C#) 0 Answers