- Home /
Separate setting music volume and sfx in one scene
Here is my script that attached to the UI button, on touch enables/disables music. I'd like to add another button, that will on touch turn on/off sfx and only sfx, independently from music.
I don't know how to do it, if someone could me explain it or show a code, it would be awesome :)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MusicOnOff : MonoBehaviour {
Text Sound;
public bool CanMute = false;
public static bool pauza = false;
public static int level1;
void Start () {
level1 = PlayerPrefs.GetInt("level1", -1);
if (pauza)
AudioListener.pause = true;
else
AudioListener.pause = false;
Sound = GameObject.Find ("Sound").GetComponent<Text> ();
}
void Update () {
if (level1 < 0) {
Sound.text = ("Touch to turn off music");
AudioListener.pause = false;
pauza = false;
}
else if (level1 > 0) {
Sound.text = ("Touch to turn on music");
pauza = true;
AudioListener.pause = true;
}}
public void OnTouch1(){
if (!pauza) {
AudioListener.pause = true;
CanMute = true;
level1 += 2;
PlayerPrefs.SetInt ("level1", level1);
} else if (pauza) {
AudioListener.pause = false;
CanMute = false;
level1 -= 2;
PlayerPrefs.SetInt ("level1", level1);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Bool not changing on button press 1 Answer
Click a UI button from a script 1 Answer
Get UI Button dimensions in game via script C# 1 Answer
Change button opacity using C# script? 1 Answer
Distribute terrain in zones 3 Answers