Question about dropdown menu for resolutions

Updated on December 31, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on December 31, 2017

Hey everyone i’m new in unity game dev. . And i’ve been following some tutorials and trying to create some stuff. I’ve got this issue when i want to create a drop down menu where you can pick a resolution, this is the code i’m using but this is not showing anything. it just shows an empty drop down menu with no options. If anyone can help it will be amazing, and thank you! 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
public class SettingsMenu : MonoBehaviour {
public AudioMixer audioMixer;
public Dropdown resolutionDropdown;
public void SetVolume(float volume )
{
audioMixer.SetFloat("volume",volume);
}
Resolution[] resolutions;
void Start()
{
resolutions = Screen.resolutions;
resolutionDropdown.ClearOptions();
List<string> options = new List<string>();
int currentResolutionIndex =0;
for(int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + "x" + resolutions[i].height;
options.Add(option);
if( resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
{
currentResolutionIndex=i;
}
}
resolutionDropdown.AddOptions(options);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
}
}

PS: Ignore the audio part, its for the volume ect..

Thank you!

  • Liked by
Reply