Save toggle button

Hey,

I am trying to save my toggle button all the time with the help of playerprefs. If you press the toggle button the music should be muted, but it will be unmuted again when you restart the scene…

This is my script attached to the toggle button:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class toggleMusic : MonoBehaviour
{


    public AudioSource Music;

   

    public void Start()
    {

        PlayerPrefs.GetInt("Muted");
        Music.mute = false;
       
    }



    public void ToggleSound()
    {
        if (PlayerPrefs.GetInt("Muted", 0) == 0)
        {
            PlayerPrefs.SetInt("Muted", 1);
        }
        else
        {
            PlayerPrefs.SetInt("Muted", 0);
        }

        SetSoundState();

    }

    private void SetSoundState()
    {
        if (PlayerPrefs.GetInt("Muted", 0) == 0)
        {
            AudioListener.volume = 1;
            Music.mute = false;
        }
        else
        {
            AudioListener.volume = 0;
            Music.mute = true;
        }
    }
}

When asking for help, you should say what the current version of your code actually does, and (if not obvious) how that differs from the intended result.

But the obvious thing in your code is on line 17, where you call PlayerPrefs.GetInt but then don’t do anything with the result. You probably want to set the isOn property of your Toggle. (Note that this will also trigger the OnValueChanged event of the Toggle, with whatever results that would normally have. You may need to make further changes to your code to account for that.)