- Home /
Screen.SetResolution in full screen issue
Hi fellow Uniters, i'm having an issue with the function Screen.SetResolution. I've set to modify the resolution in game (disabled the Display Resolution Dialog), but when i'm in full screen and switch resolution, i does :). But the old resolution stay in the background, i don't think that there are any errors, but if anyone here could help me i'll appreciate.
Issue 1: http://postimg.org/image/70r6l94ll/
Issue 2: http://postimg.org/image/aj36hn5hl/
PS: If i swith tabs after setting the new resolution, the little bug disappears.
PS2: To find quickly the Resolution part, ctrl+F "// Set Window Resolution
Code:
using UnityEngine;
using System.Collections;
public class _LobbyMenu : Photon.MonoBehaviour {
public AudioSource _audioComponent;
public AudioClip _windEffect;
// Variaveis dos menus GUI
public AudioClip _buttonPress;
public Texture2D _gameLogo;
public GUISkin _lobbySkin;
private float _currentMenu;
private float _screenCenterX;
private float _screenCenterY;
private int _screenResolution;
private string _whichResolution;
private int _screenQuality;
private string _whichQuality;
private bool _fullScreen;
void Start ()
{
audio.loop = true;
audio.clip = _windEffect;
audio.volume = 0.25f;
audio.PlayDelayed (1);
_currentMenu = 0;
if (PlayerPrefs.GetInt("_fullScreen") == 0)
_fullScreen = true;
if (PlayerPrefs.GetInt("_fullScreen") == 1)
_fullScreen = false;
_whichResolution = "";
_screenResolution = PlayerPrefs.GetInt ("_screenResolution");
_whichQuality = "";
_screenQuality = PlayerPrefs.GetInt ("_screenQuality");
Debug.Log (QualitySettings.names.Length);
}
void Update ()
{
_screenCenterX = Screen.width / 2;
_screenCenterY = Screen.height / 2;
transform.Rotate(Vector3.up * Time.deltaTime, Space.World);
}
void OnGUI ()
{
GUI.skin = _lobbySkin;
if(_currentMenu == 0) StartMenu();
if(_currentMenu == 1) SinglePlayerMenu();
if(_currentMenu == 2) MultiPlayerMenu();
if(_currentMenu == 3) OptionsMenu();
if(_currentMenu == 4) ExitMenu();
}
void StartMenu ()
{
GUI.DrawTexture (new Rect(_screenCenterX - 512/2, _screenCenterY - 64 * 2, 512, 64), _gameLogo);
GUI.BeginGroup (new Rect(_screenCenterX - 256/2, _screenCenterY, 256, 128+15));
if(GUI.Button (new Rect(0, 0, 256, 32), "Single Player"))
{
audio.PlayOneShot(_buttonPress);
_currentMenu = 1;
}
if(GUI.Button (new Rect(0, 37, 256, 32), "Multi Player"))
{
audio.PlayOneShot(_buttonPress);
}
if(GUI.Button (new Rect(0, 74, 256, 32), "Options"))
{
audio.PlayOneShot(_buttonPress);
_currentMenu = 3;
}
if(GUI.Button (new Rect(0, 111, 256, 32), "Exit"))
{
audio.PlayOneShot(_buttonPress);
}
GUI.EndGroup ();
}
void SinglePlayerMenu ()
{
GUI.DrawTexture (new Rect(_screenCenterX - 512/2, _screenCenterY - 64 * 2, 512, 64), _gameLogo);
GUI.BeginGroup (new Rect(_screenCenterX - 256/2, _screenCenterY, 256, 64+5));
GUI.Box (new Rect(0, 0, 256, 32), "The following feature is desabled.");
if(GUI.Button (new Rect(0, 37, 256, 32), "Back"))
{
audio.PlayOneShot(_buttonPress);
_currentMenu = 0;
}
GUI.EndGroup ();
}
void MultiPlayerMenu ()
{
}
void OptionsMenu ()
{
GUI.DrawTexture (new Rect(_screenCenterX - 512/2, _screenCenterY - 64 * 2, 512, 64), _gameLogo);
GUI.BeginGroup (new Rect(_screenCenterX - 256/2, _screenCenterY, 256, 256));
GUI.Box(new Rect(0, 0, 256, 182), "");
// Set Window Resolution
GUI.Label(new Rect(10, 10, 236, 25), "Resolution: " + _whichResolution);
_screenResolution = Mathf.RoundToInt(GUI.HorizontalSlider(new Rect(10, 40, 236, 30), _screenResolution, 0, 6));
if (_screenResolution == 0)
_whichResolution = "800 x 600";
if (_screenResolution == 1)
_whichResolution = "1024 x 768";
if (_screenResolution == 2)
_whichResolution = "1280 x 600";
if (_screenResolution == 3)
_whichResolution = "1280 x 720";
if (_screenResolution == 4)
_whichResolution = "1280 x 768";
if (_screenResolution == 5)
_whichResolution = "1360 x 768";
if (_screenResolution == 6)
_whichResolution = "1366 x 768";
// Set Image Quality
GUI.Label(new Rect(10, 75, 236, 25), "Quality: " + _whichQuality);
_screenQuality = Mathf.RoundToInt(GUI.HorizontalSlider(new Rect(10, 105, 236, 30), _screenQuality, 0, 4));
if (_screenQuality == 0)
_whichQuality = "Fast";
if (_screenQuality == 1)
_whichQuality = "Simple";
if (_screenQuality == 2)
_whichQuality = "Good";
if (_screenQuality == 3)
_whichQuality = "Beautiful";
if (_screenQuality == 4)
_whichQuality = "Fantastic";
GUI.Label(new Rect(10, 140, 236, 25), "Full Screen ");
_fullScreen = GUI.Toggle(new Rect(85, 143, 16, 16), _fullScreen, "");
if(GUI.Button (new Rect(0, 256 - 69, 256, 32), "Apply"))
{
audio.PlayOneShot(_buttonPress);
if (_screenResolution == 0)
Screen.SetResolution(800, 600, _fullScreen);
if (_screenResolution == 1)
Screen.SetResolution(1024, 768, _fullScreen);
if (_screenResolution == 2)
Screen.SetResolution(1280, 600, _fullScreen);
if (_screenResolution == 3)
Screen.SetResolution(1280, 720, _fullScreen);
if (_screenResolution == 4)
Screen.SetResolution(1280, 768, _fullScreen);
if (_screenResolution == 5)
Screen.SetResolution(1360, 768, _fullScreen);
if (_screenResolution == 6)
Screen.SetResolution(1366, 768, _fullScreen);
if (_screenQuality == 0)
QualitySettings.SetQualityLevel(1, true);
if (_screenQuality == 1)
QualitySettings.SetQualityLevel(2, true);
if (_screenQuality == 2)
QualitySettings.SetQualityLevel(3, true);
if (_screenQuality == 3)
QualitySettings.SetQualityLevel(4, true);
if (_screenQuality == 4)
QualitySettings.SetQualityLevel(5, true);
PlayerPrefs.SetInt("_screenResolution", _screenResolution);
PlayerPrefs.SetInt("_screenQuality", _screenQuality);
if(_fullScreen == true)
PlayerPrefs.SetInt("_fullScreen", 0);
else
PlayerPrefs.SetInt("_fullScreen", 1);
}
if(GUI.Button (new Rect(0, 256 - 32, 256, 32), "Back"))
{
audio.PlayOneShot(_buttonPress);
_currentMenu = 0;
}
GUI.EndGroup ();
}
void ExitMenu ()
{
}
}
How do you know the device supports those resolutions?
Also: http://forum.unity3d.com/threads/unity-max-resolution-error.289333/ may be related.
i tried in my 1366x768 monitor and a small one, the same error occurred