Changing screen resolution with GUI Buttons

Hello everyone, I am having the greatest of troubles with changing resolutions within the game. A little help? What I am trying to do is have a set of buttons that when each is clicked, they change the resolution. Here is my script.

 //defaultres
(Screen.SetResolution(1920,1080,true));


//button
var bsize : int;
var cguis : GUIStyle;
//toggle
private var toggleTxt : boolean = false;

function OnGUI() {
	GUI.Box(Rect(0,0,Screen.width,Screen.height),"");
	
	GUI.Box(Rect(Screen.width/5,Screen.height/20,800,20),"Video Options", cguis);
	
	GUI.Toggle(Rect(Screen.width/12.2,Screen.height/1.23,120,20),toggleTxt,"Toggle Fullscreen");
	
	GUI.Button(Rect(Screen.width/20,Screen.height/6,bsize,bsize*.3),"800x600");
		
	GUI.Button(Rect(Screen.width/20,Screen.height/3.5,bsize,bsize*.3),"1024x768");
	GUI.Button(Rect(Screen.width/20,Screen.height/2.45,bsize,bsize*.3),"1280x600");
	GUI.Button(Rect(Screen.width/20,Screen.height/1.89,bsize,bsize*.3),"1280x960");
	GUI.Button(Rect(Screen.width/20,Screen.height/1.52,bsize,bsize*.3),"1360x768");
	GUI.Button(Rect(Screen.width/4,Screen.height/6,bsize,bsize*.3),"1400x1050");
	GUI.Button(Rect(Screen.width/4,Screen.height/3.5,bsize,bsize*.3),"1600x900");
	GUI.Button(Rect(Screen.width/4,Screen.height/2.45,bsize,bsize*.3),"1680x1050");
	GUI.Button(Rect(Screen.width/4,Screen.height/1.89,bsize,bsize*.3),"1920x1080");
}

Gui.Button returns a boolean, so you can see when it’s clicked:

if (GUI.Button(Rect(Screen.width / 20, Screen.height / 6, bsize, bsize * 0.3f), "800x600"))
    Screen.SetResolution(800, 600, true);

You could save yourself a lot of pain by writing a general case method:

private void _DrawResolutionButton(Rect position, int x, int y)
{
    string niceName = string.Format("{0}x{1}", x, y);
    
    if (GUI.Button(position, niceName))
        Screen.SetResolution(x, y, true);
}