I have made a button to turn off audio, it works great, but if I click the button again…
How do I get the audio to be unpaused.
using UnityEngine;
using System.Collections;
public class Soundoff : MonoBehaviour {
public Texture2D icon;
void OnGUI () {
if (GUI.Button (new Rect (10,120, 100, 50), icon)) {
AudioListener.pause = true;
if (GUI.Button (new Rect (10,140, 100, 50), icon)) {
AudioListener.pause = false;
}
}
}
}
Okay I got it to Unpause. didnt put it in update.
But now I have a error code and it takes at least 2 minutes to unpause.
this is the error
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUI.Button (Rect position, UnityEngine.Texture image) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/GUI.cs:333)
Soundoff.Update () (at Assets/Soundoff.cs:16)
using UnityEngine;
using System.Collections;
public class Soundoff : MonoBehaviour {
public Texture2D icon;
void OnGUI () {
if (GUI.Button (new Rect (10,120, 90, 50), icon)) {
AudioListener.pause = true;
}
}
void Update() {
if (GUI.Button (new Rect (10,120, 90, 50), icon)) {
AudioListener.pause = false;
}
}
}