Question by
SynGT · Mar 28, 2016 at 12:30 AM ·
javascriptobjecttoggletoggle button
Cannot convert void to UnityEngine.UI.Toggle.ToggleEvent - Javascript
I realize I'm probably doing something stupid, but I'm not great w/ Javascript. Anyways, the code probably explains what I'm trying to do. Set music preferences on a toggle switch, saved in user preferences, which will activate music later. But I'm getting the above error for the life of me can't figure it out.
#pragma strict
function MusicOnOff () {
var newToggle : UnityEngine.UI.Toggle;
newToggle.onValueChanged = SetMusicPrefs();
}
function SetMusicPrefs () {
var musToggle : GameObject = GameObject.Find("MusicToggle");
var musicOnOff : int = PlayerPrefs.GetInt("MusicOnOff", 0);
if (musToggle.GetComponent(UnityEngine.UI.Toggle).isOn) {
PlayerPrefs.SetInt("MusicOnOff", 1);
PlayerPrefs.Save();
} else if (!musToggle.GetComponent(UnityEngine.UI.Toggle).isOn) {
PlayerPrefs.SetInt("MusicOnOff", 0);
PlayerPrefs.Save();
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612073416im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My music player is getting detached from toggle after changing scenes 0 Answers
Need help understanding toggle code. 0 Answers
How to add a script to a parent object and not every individual child object. 1 Answer
Toggling checkbox in toggle in GUILayout.Toggle 1 Answer
Toggle Group save stats 0 Answers