unity toggle set interactive code example

Example 1: how to save toggle values unity

public Toggle Toggle;

    private void Start() {
        if ((PlayerPrefs.GetInt("ToggleBool") == 1)) {
            Toggle.isOn = true
        }
        else {
            Toggle.isOn = false;
        }
    }

    private void Update() {
        if (Toggle.isOn == true) {
            PlayerPrefs.SetInt("ToggleBool", 1);
        }
        else {
            PlayerPrefs.SetInt("ToggleBool", 0);
        }

Example 2: how to use toggle in unity

using.UnityEgnigne.UI;

public class ToggleScript : MonoBehaviour
{

public Toggle toggle;

void Update()
{
	if(toggle.isOn)
    {
    //Do stuff
    }
}
}