- Home /
How to make a Horizontal Slider slide between resolutions?
I just cant imagine how to do it. What I would like, is a horizontal slider, that you can slide with to choose resolution. Then you click a button and it will apply what you have chosen. Any ideas? I've look at docs and googled something similar, but my mind just cant imagine it. Any help appreciated, thanks in advance. Last resort is to use a ton of buttons, but that's just.. weird.. lol.
Answer by Professor Snake · Nov 21, 2013 at 04:05 PM
Building up on tbkn's answer. You can get all the available resolutions wwith Screen.resolutions (an array of type Resolution). You can then create a variable that is modified by the HorizontalSlider and is used as an index to point values in the Screen.resolutions array:
var resolutionPointer:int=0;
function OnGUI(){
resolutionPointer=GUI.HorizontalSlider(sliderRect,resolutionPointer,0,Screen.resolutions.length);
if(GUI.Button(buttonRect,"Apply")
Screen.SetResolution(Screen.SetResolution(Screen.resolutions[resolutionPointer].width,Screen.resolutions[resolutionPointer].height,true); ,true);
}
This confuses me, here's what I tried.
if (ShowFullScreenOption == true) {
resolutionPointer=GUI.HorizontalSlider(FitAllRes(Rect(465,350,10,10),resolutionPointer,0,Screen.resolutions.length);
if(GUI.Button(FitAllRes(Rect(465,400,100,150)),"Apply"))
Screen.SetResolution(Screen.resolutions[resolutionPointer],true);
Can you point out what I screwed up? I have the variable set up ofcourse, and just ignore the if (ShowFullScreenOption) since that is just for making it visible when a button is pushed
the FitAllRes is a fuction for making the GUI resize depending on resolution
I'm missing something I just dont know what and where to put it.
What seems to be the error? Edit: Whoops. I meant Screen.SetResolution(Screen.resolutions[resolutionPointer].width,Screen.resolutions[resolutionPointer].height,true);
I fixed most of the errors, now the last one is (176,25): BCE0023: No appropriate version of 'UnityEngine.Screen.SetResolution' for the argument list '(UnityEngine.Resolution, boolean)' was found.
Error is in Screen.SetResolution(Screen.resolutions[resolutionPointer],true);
Okay I figured it out. It works, except it makes it full screen when switching. What I was thinking, is sliding between 19 differnet resolutions. How would I go about that? $$anonymous$$aking it so if it's at 1, it says 640*480 in a label, then if it slides one more time to 2, it says 720*480, then on and on till 19. Sorry for so much trouble with me, thanks in advance.
$$anonymous$$ake the third argument to SetResolution be false ins$$anonymous$$d of true if you don't want it to go fullscreen. For your label, just do GUI.Label(labelRect,Screen.resolutions[resolutionPointer].width+"x"+Screen.resolutions[resolutionPointer].height);
Answer by Panik.Studios · Nov 21, 2013 at 04:21 PM
x= Number Of Resolution
Create a GUI slider just like you would any other say for volume
I dont know how to make an option for resoltion but Im sure you can find out how on here.
But I would assign a value to each resolution exmple 480p = 1 ; 720p = 2 ; 1080p = 3 ;
Im pretty sure the slider will snap to 1 2 3 based on how you write the var
Answer by Tomer-Barkan · Nov 21, 2013 at 03:50 PM
First, to find out how to change resolutions, read here:
http://docs.unity3d.com/Documentation/ScriptReference/Screen.SetResolution.html
Second, you just have to create a GUI slider component:
http://docs.unity3d.com/Documentation/ScriptReference/GUI.HorizontalSlider.html
Now all you have to do is connect the two. In a script, create a slider, and give it min value 0 and max value equal the number of resolution options you have. Now in that script, check the value of the slider, rounded down to the latest whole number. When the player clicks apply, change resolution based on that number.
Sample code:
public class ResolutionSelector : MonoBehaviour {
public float hSliderValue = 0.0F;
public int[,] resolutions = { {640, 480}, {1280, 1024}, {1920, 1080} }
void OnGUI() {
hSliderValue = GUI.HorizontalSlider(new Rect(25, 25, 100, 30), hSliderValue, 0.0F, 3.0f);
if (GUI.Button(new Rect(25, 70, 100, 30), "Apply")) {
int resolutionIndex = Mathf.FloorToInt(hSliderValue);
Screen.SetResolution(resolutions[resolutionIndex, 0], resolutions[resolutionIndex, 1], true);
}
}
}
Your answer
Follow this Question
Related Questions
GUI slider and rotation not working 1 Answer
how to make a Horizontal slider & toggle in C# with GUI textures 1 Answer
GUI Sliders in the same script. Question (Js.) 1 Answer
Horizontal Slider issue 0 Answers
Curving an Horizontal Slider 2 Answers