0
\$\begingroup\$

When I open my game the fullscreen box is checked, but the game is windowed. If I uncheck and check the box it will go into fullscreen. What is the fix?

public class Settings : MonoBehaviour
{

   public void SetFullscreen (bool isFullscreen)
{
    Screen.fullScreen = isFullscreen;
}
}

I save the current display resolution when the player hits the quit button

    public void Quit()
{
#if UNITY_EDITOR
    UnityEditor.EditorApplication.isPlaying = false;
#else
    Application.Quit();
#endif
}

enter image description here

\$\endgroup\$
4
  • \$\begingroup\$ @DMGregory really tired sorry ignore the message about saving. The scrren resolution automatically restores to the last state, but I still have not figured out how to make the checkbox be unchecked if the player starts in windowed mode. \$\endgroup\$
    – Ethan K-B
    Commented Aug 7, 2019 at 3:13
  • \$\begingroup\$ Presumably you tried reading the current fullscreen state in Start() and modifying the checkbox state to match? How did that work out? \$\endgroup\$
    – DMGregory
    Commented Aug 7, 2019 at 3:14
  • \$\begingroup\$ @DMGregory no not sure how to make the checkbox state match at the start. It always starts checked, but changes when I change modes. \$\endgroup\$
    – Ethan K-B
    Commented Aug 7, 2019 at 3:16
  • \$\begingroup\$ @DMGregory I missed the hyperlink. I read it, but am unsure of how to apply it. \$\endgroup\$
    – Ethan K-B
    Commented Aug 7, 2019 at 5:20

1 Answer 1

1
\$\begingroup\$

Remember, video games, and the computers that run them, are just machines. They do only what you tell them to, in the order you tell them to do it.

Right now, you only tell the machine "make the game's fullscreen state match this UI toggle" in the callback method after the player clicks it:

public void SetFullscreen (bool isFullscreen)
{
    Screen.fullScreen = isFullscreen;
}

If you want "to make the checkbox be unchecked if the player starts in windowed mode" then you have two steps:

  1. Run some code at the start (say, on game start-up, or when the Settings screen is shown)

    You can do this in a MonoBehaviour by making a method called Start() or OnEnable()

  2. Inside that code, tell the game to change the toggle's checked state to match the current windowed state: fullscreenToggle.isOn = Screen.fullScreen;

Putting it together, it could look like this:

using UnityEngine.UI;

public class Settings : MonoBehaviour {

    // Populate this in the Inspector to point to your fullscreen toggle checkbox.
    public Toggle fullscreenToggle;

    // Run some code in the frame when this instance spawns.
    void Start() {
        // Match UI control state to current fullscreen/windowed state of the game.
        fullscreenToggle.isOn = Screen.fullScreen;

        // Do the rest of your Start() work...
    }

    // When the player clicks the toggle, update the game's fullscreen/windowed state.
    public void SetFullscreen (bool isFullscreen) {
        Screen.fullScreen = isFullscreen;
    }

    // Do the rest of your input handling...
}
\$\endgroup\$
1
  • \$\begingroup\$ Oh my god. Thank you so much. It seems really obvious now. \$\endgroup\$
    – Ethan K-B
    Commented Aug 7, 2019 at 16:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .