Get each resolution and store them

I

In the screenshot below i have a left arrow gui text (<), a right arrow gui text (>) and the resolution gui text in the middle. In the resolution gui text i want the script to get all the resolutions supported for the user’s monitor but not display them just get them. I guess i need the script to have a loop and get all the resolutions. Once the script gets the resolutions i want it to store them somewhere. If it’s possible for each resolution to have an id so i can use them later with another script on the left and right arrow gui texts. The right arrow will move to the next available resolution and the left arrow will move to the previous resolution.

You could store them with GUI buttons like this:

if(GUI.Button(Rect(Screen.width/2 - -0, Screen.height/2 - 60, 100, 30), "fill out the buttons info")) {
Screen.SetResolution(?, ?, (windowed mode) true or false?);                                                                           		
//Your resolutions:
ResX = ?;
ResY = ?;

You said “store them”, but I think you mean something different. Usually “store” means “save this data somewhere so it can be accessed later”, which seems a little pointless when you can just use “Screen.resolutions” any time you want to check the available resolutions.

Having said that, I still don’t understand what you need to do. By “store each resolution in my script” I guess you want to have a member that’s set in the Start method and can be used in other methods of the script. If that’s correct, instead of using a variable inside the method, define a variable for the whole class. Something like this:

#pragma strict

var resolutions: Resolution[];

function Start ()
{
    resolutions = Screen.resolutions;
}

function AnotherFunction ()
{
    for(var res in resolutions)
    {
        //do something
    }
}

For the second question “how do i call a resolution?”… resolutions are not “called”, a resolution is just a size, you set the screen resolution. Mafia2Smoke already told you how to set the screen resolution.

If you meant something else please explain what you want to do better.

I got it working guys. Thank you so much everyone and especially @DiegoSLTS. You helped a lot with that last script. Everything is working in the exe of course because in the builder you can’t change resolution. Here is the script for anyone that needs it. (I will mark my answer as correct so just anyone can see it but credits to you guys, thanks again).

#pragma strict
 
var resIndex : int = 0;
var resolutions: Resolution[];

function Start ()
{
resolutions = Screen.resolutions;
}

function Update ()
{
GetComponent.<GUIText>().text = resolutions[resIndex].width + "x" + resolutions[resIndex].height;
}

function PreviousResolution ()
{
resIndex--;	
	if(resIndex < 0)
	{
	resIndex = Screen.resolutions.Length -1;
	}
}

function NextResolution ()
{
resIndex++;
	if(resIndex > Screen.resolutions.Length -1)
	{
	resIndex = 0;
	}
}

function OnMouseUp ()
{
Screen.SetResolution(resolutions[resIndex].width, resolutions[resIndex].height, true);
}