Beginner Question about toggle fullscreen and window mode.

Hi…
So I am kind of new to unity and C# and working on a project.
Right now I am stuck in setting panel. I put a toggle to turn the game window in to fullscreen and back to window mode.
tried so many scripts and spend couple of hours searching on google.
any how.I do not want to use a key to change to fullscreen.
did try:
screen.fullscreen = !screen.fullscreen;
and bunch of variables of this but nothing seems to be working.

just want the toggle function to switch between fullscreen and window mode.

Can someone help please.

thank you and have a great day/night.

Case is important for the class and variable. It’s literally:

Screen.fullScreen = !Screen.fullScreen;

Capital S in both.

so here is what I do…

  1. I made a script called Settings.cs

using UnityEngine;
using UnityEngine.UI;

public class Settings : MonoBehaviour {

public Slider Volume;
public AudioSource GameMusic;

// Use this for initialization
void Start ()
{

}

void ToggleFullScreen()
{
Screen.fullScreen = !Screen.fullScreen;
}

// Update is called once per frame
void Update ()
{
GameMusic.volume=Volume.value;
}

}

  1. attached Setting.cs it to my gamemanager
  2. on a toggle I am trying to use it…
    on Value changed(boolean), runtime only, gamemanager attached but not seeing ToggleFullScreen function :frowning:

hmm got it working…

made a new script called fullscreen.cs
attached that one to my gamemanager and it works now.
no idea why it didnt work before

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

public class fullscreen : MonoBehaviour
{

public void fullscreenonoff()
{
if (Screen.fullScreen == true) {
Screen.fullScreen = false;
} else {
Screen.fullScreen = true;
}
}
}

now off to figuring resolution changes. :slight_smile:

I know this is an old post, but the answer is that you have to set the function to public. If it’s a private void, then you’re not going to be able to access the function outside of the script itself.

2 Likes