- Home /
How to change the display at runtime.
I read this. But simply changing "UnitySelectMonitor" Player Pref only works after restarting the game.
I have arrow buttons to let the user change to the previous or the next available monitor. Here is the code example for the next monitor button.
public Resolution[] resolutions;
public int curRes;
public int curMonitor = 0;
public int curWidth, curHeight;
public bool curFullscreen = true;
public void nextMonitor()
{
curMonitor++;
//checking if there is another monitor
if (curMonitor > Display.displays.Length - 1)
curMonitor = 0;
//setting PlayerPref
PlayerPrefs.SetInt("UnitySelectMonitor", curMonitor);
//calculating available resolutions
resolutions = Screen.resolutions;
curRes = resolutions.Length - 1;
//sets the best resolution
curWidth = resolutions[curRes].width;
curHeight = resolutions[curRes].height;
Screen.SetResolution(curWidth, curHeight, curFullscreen);
}
Here are my PlayerSettings:
unbenannt.png
(20.2 kB)
Comment
I've been using the this in my code as well, and after some testing I can confirm that this is a problem with Unity 2017. I've submitted a bug report, but at the moment it looks like the only solution is to use an older version of unity.
Answer by Raxreedoroid · Jan 01, 2021 at 07:14 PM
public void ChangeDisplay(Camera camera)
{
Camera cur = Camera.current;
camera.targetDisplay = 0;
cur.targetDisplay = 5;
}
I use this code it is very simple!
It switches cameras displays
You are the best!! I've been looking for a solution for days. But how does it work?