Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Fullscreen toggle does not save / set

Discussion in 'Scripting' started by LifeSymbiont, Dec 6, 2021.

  1. LifeSymbiont

    LifeSymbiont

    Joined:
    Apr 19, 2015
    Posts:
    36
    Hello, I am currently writing a saving option that sets the fullscreen based on the UI toggle on start of the game, so the player does not have to set the fullscreen every time the game starts but just sets it the way it was set last time.
    I don't get any bugs with the code, but it does not set the fullscreen off on start even though it was set that way last time.
    Please help me

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.Rendering;
    6. using UnityEngine.Rendering.HighDefinition;
    7. public class FullScreenToggle : MonoBehaviour
    8. {
    9.     public Toggle myToggle;
    10.     public void Start()
    11.     {
    12.         if(PlayerPrefs.GetInt("fullScreenSave") == 1)
    13.         {
    14.             Screen.fullScreen = true;
    15.         }
    16.      
    17.         if(PlayerPrefs.GetInt("fullScreenSave") == 0)
    18.         {
    19.             Screen.fullScreen = false;
    20.         }
    21.     }
    22.  
    23.     void Update()
    24.     {
    25.         if(myToggle.isOn == true)
    26.         {
    27.             Screen.fullScreen = true;
    28.             PlayerPrefs.SetInt("fullScreenSave", 1);
    29.         } //else Screen.fullScreen = false;
    30.  
    31.         if(myToggle.isOn == false)
    32.         {
    33.             Screen.fullScreen = false;
    34.             PlayerPrefs.SetInt("fullScreenSave", 0);
    35.         }
    36.     }
    37. }
    38.  
    39.  
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,886
    LifeSymbiont likes this.
  3. LifeSymbiont

    LifeSymbiont

    Joined:
    Apr 19, 2015
    Posts:
    36