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:
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()
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...
}