- Home /
This question was
closed Apr 18, 2021 at 07:06 PM by
wolfgangmami for the following reason:
I solved it
Question by
wolfgangmami · Mar 21, 2021 at 05:10 PM ·
c#programmingresolutionprogramming-basics
Dropdown resolutions menu
Hi I'm following this video but I'm not doing it right. Something in the code messing up things. First dropdown menu is always giving me 0 index value, no matter what. Second In the code triggering unwanted behavior (onvaluechanged script). There is a not much source to do it right. Please help.
Resolution[] _resolutions;
public Dropdown _res_dropdown;
void Start()
_resolutions = Screen.resolutions;
_res_dropdown.ClearOptions();
List<string> options = new List<string>();
int currenResolutionIndex = 0;
for (int i = 0; i < _resolutions.Length; i++)
{
if (_resolutions[i].refreshRate > 59)
{
string option = _resolutions[i].width + " x " + _resolutions[i].height + " " + _resolutions[i].refreshRate + " Hz";
options.Add(option);
}
if (_resolutions[i].width == Screen.currentResolution.width && _resolutions[i].height == Screen.currentResolution.height)
{
currenResolutionIndex = i;
}
}
_res_dropdown.AddOptions(options);
_res_dropdown.value = currenResolutionIndex;
_res_dropdown.RefreshShownValue();
}
public void resolution(int Index)
{
Debug.Log(Index);
Resolution resolution = _resolutions[Index];
if (Screen.fullScreenMode == FullScreenMode.FullScreenWindow)
{ Screen.SetResolution(resolution.width, resolution.height, FullScreenMode.FullScreenWindow); }
else
{ Screen.SetResolution(resolution.width, resolution.height, FullScreenMode.Windowed); }
}
Comment