- Home /
Fullscreen Toggle Issue
Hi all, fullscreen toggling should be a relativley simple thing to sort out, but ever since day one I've had a problem which I cant seem to solve.
The following function runs all the time (from the update) and waits for a key input, no problems there and infact the variable isFullScreen gets changed as required, however the screen doesnt go fullscreen until you press the buttons again..and of course at that point the var gets set back to false so effectiveley the code works but ONLY if you press the buttons twice each time you want to toggle. Any ideas?
function FullScreenToggle() { fullScreenToggleKeyPressed= Input.GetKeyDown(fullScreenToggleKey);
if(fullScreenToggleKeyPressed&&Input.GetKey (KeyCode.LeftShift)&&Input.GetKey (KeyCode.LeftAlt))
{
if (isFullScreen==false)
{
//this is some kind of error need to try !Screen.fullScreen; ? To test neeed a separate build.
Screen.fullScreen = Screen.fullScreen;
isFullScreen=true;
return;
}
if (isFullScreen)
{
Screen.fullScreen = !Screen.fullScreen;
isFullScreen=false;
return;
}
}
}
Replace the inner two ifs with "Screen.fullScreen = !Screen.fullScreen;"
I dont understand what you mean. Do you mean replace both of the complete IF statements with one line? If so, where does my isFullScreen:boolean; statement go?
Could you perhaps cut and paste an example using the above code? Cheers
On Windows, Press the 'windows key' (between CTRL and ALT), and the 'right arrow' at the same time. It pushes the window to the right which exits full screen with a keyboard shortcut.
Answer by Chris 24 · Jan 24, 2011 at 10:59 AM
Is this in the webplayer? If so, thats been designed so that the user needs to click on the screen to allow it to go into fullscreen mode.
It is in the webplayer but this happens when the player is already in focus.
..or do you mean that there is an additional click required..? If so why and how do I get around it?
Answer by Gillissie · Apr 20, 2011 at 01:33 AM
Your problem is this line of code, which doesn't do anything:
Screen.fullScreen = Screen.fullScreen;
You don't really need to use a variable to keep track of isFullScreen. Simply read Screen.fullScreen to find out if it is currently full screen.
Answer by MMortal · Aug 21, 2013 at 10:09 PM
Here is how I got it to work for me (c#):
void Update(){
if(Input.GetKeyUp(KeyCode.F))
ToggleFullScreen();
}
void ToggleFullScreen(){
if(Screen.fullScreen= !Screen.fullScreen){
Screen.fullScreen = Screen.fullScreen;
Screen.SetResolution(Screen.width, Screen.height, true, 60);
}else{
Screen.fullScreen = !Screen.fullScreen;
}
Hope it helps somebody.
You said Screen.fullScreen = Screen.fullScreen; doesn't do anything but there is the same line in your example.