Created
August 26, 2017 01:33
-
-
Save QubitsDev/12227a7164f1ae99c1a7537c5c98068c to your computer and use it in GitHub Desktop.
Automatic quality level dropdown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
[RequireComponent(typeof(Dropdown))] | |
public class QualityDropdown : MonoBehaviour | |
{ | |
private Dropdown m_Dropdown; | |
/// <summary> | |
/// Start is called on the frame when a script is enabled just before | |
/// any of the Update methods is called the first time. | |
/// </summary> | |
void Start() | |
{ | |
m_Dropdown = GetComponent<Dropdown>(); | |
m_Dropdown.options.Clear(); | |
for (int i = 0; i < QualitySettings.names.Length; i++) | |
{ | |
m_Dropdown.options.Add(new Dropdown.OptionData(QualitySettings.names[i])); | |
m_Dropdown.onValueChanged.AddListener(QualitySettings.SetQualityLevel); | |
} | |
// Set current quality level. | |
m_Dropdown.value = QualitySettings.GetQualityLevel(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need add listener once only.
You can also reduce line count with this: