My code works, currently I’m working on the audio and this script makes it all work smoothly other then the fact that if I leave the scene and come back (audio still working fine) and go back to the place where the toggle is, the toggle with be true, even if it should be false (aka the music is off)(And the music is not playing, and to turn it on I have to uncheck the toggle (again giving the value to off, and then turning it back to on again); this will make sense after seeing the code (the MusicBool function runs on value change of the toggle):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MusicScriptFinally : MonoBehaviour
{
public GameObject Music;
public void Start()
{
CheckMusic();
}
public void CheckMusic()
{
if (PlayerPrefs.HasKey("MusicOn"))
{
if (PlayerPrefs.GetInt("MusicOn") > 0)
{
Music.SetActive(true);
}
else
{
Music.SetActive(false);
}
}
else
{
PlayerPrefs.SetInt("MusicOn", 1);
Music.SetActive(true);
}
}
public void MusicBool(bool value)
{
if (value == true)
{
PlayerPrefs.SetInt("MusicOn", 1);
}
else
{
PlayerPrefs.SetInt("MusicOn", 0);
}
CheckMusic();
}
}