Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

Save a Toggle Group state?

$
0
0
Hi, Here is my current music mute code, which works perfectly. just what i need. but can't get the state of the toggle to stay as it should when resetting the scene. Thanks to anyone who can help! using UnityEngine; using System.Collections; using UnityEngine.UI; public class PauseMenuScriptToggle : MonoBehaviour { const float DefaultVolumeLevel = 1.0f; bool isMute; public bool isOn; void Start() { audio.volume = PlayerPrefs.HasKey("CurVol") ? PlayerPrefs.GetFloat("CurVol") : DefaultVolumeLevel; } public void MusicMute () { if(isMute == true){ Debug.Log("Music On"); audio.volume = 1.0f; isMute = false; } else { Debug.Log("Music Off"); isMute = true; audio.volume = 0; } PlayerPrefs.SetFloat("CurVol", audio.volume); PlayerPrefs.Save(); } }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>