- Home /
Problem making list from resolutions.
I've been trying to make a list containing all the resolutions that the player's monitor can support. I've tried two different methods both resulting in an error. I'm not sure if I'm making a stupid mistake or if I'm way off. I thought one of these would work based off what I read here: http://docs.unity3d.com/Documentation/ScriptReference/Screen-resolutions.html
This first one prevents me from building the game giving off the message "Cannot convert 'UnityEngine.Resolution' to 'int'.".
for (var res in resolutions) {
if (GUILayout.Button (res.width.ToString() + " x " + res.height.ToString())) {
cursor.audio.Play();
Screen.SetResolution (resolutions[res].width, resolutions[res].height, true);
}
}
The second one only creates an error when I open the window. It displays "MissingFieldException: Field 'System.Int32.width' not found." as well as "ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint".
for (var res : int = 0; res < resolutions.Length; res++) {
if (GUILayout.Button (res.width.ToString() + " x " + res.height.ToString())) {
cursor.audio.Play();
Screen.SetResolution (resolutions[res].width, resolutions[res].height, true);
}
}
Answer by Landern · Jan 04, 2013 at 04:08 AM
try this:
for (var res : Resolution in Screen.Resolutions) {
if (GUILayout.Button (res.width.ToString() + " x " + res.height.ToString())) {
cursor.audio.Play();
Screen.SetResolution (res.width, res.height, true);
}
}
Answer by Eric5h5 · Jan 04, 2013 at 04:04 AM
In the first case:
for (var res in resolutions) {
Screen.SetResolution (resolutions[res].width, resolutions[res].height, true); <--
You defined "res" as a Resolution; you can't use it as an integer index for an array. Look at the code two lines above and use that technique instead.
In the second case:
for (var res : int = 0; res < resolutions.Length; res++) {
if (GUILayout.Button (res.width.ToString() + " x " + res.height.ToString())) { <--
You defined "res" as an integer; you can't use it as a Resolution. Look at the the code two lines below and use that technique instead.