- Home /
Question by
Aliteaon · Feb 18, 2021 at 10:04 PM ·
c#resolution settings
Does this resolution code get executed depending on the computer the player is using?
So i wrote this code to allow the player to change resolutions. My question is, are the options, that will be displayed in the dropdown, going to be different for each computer? On my laptop the highest resolution option is 1366x768, so if a player uses a better PC to play the game, does he get the option for a better resolution? Here's the code:
public Dropdown resolutionDropdown; Resolution[] resolutions;
void Start()
{
resolutions = Screen.resolutions;
resolutionDropdown.ClearOptions();
int currentResolution = 0;
List<string> dropdownOptions = new List<string>();
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + "x" + resolutions[i].height;
dropdownOptions.Add(option);
if(resolutions[i].width == Screen.width && resolutions[i].height == Screen.height)
{
currentResolution = i;
}
}
resolutionDropdown.AddOptions(dropdownOptions);
resolutionDropdown.value = currentResolution;
resolutionDropdown.RefreshShownValue();
}
public void SetResolution(int resolutionIndex)
{
Resolution resolution = resolutions[resolutionIndex];
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
}
Comment
Answer by MUG806 · Feb 20, 2021 at 04:17 PM
lmgtfy
- https://docs.unity3d.com/ScriptReference/Screen-resolutions.html"Unity returns the resolutions the monitor supports"