Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Madswint · Nov 21, 2013 at 02:51 PM · guiresolutionsliderhorizontal-slider

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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);      
 }
Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Madswint · Nov 21, 2013 at 04:25 PM 0
Share

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.

avatar image Professor Snake · Nov 21, 2013 at 04:34 PM 0
Share

What seems to be the error? Edit: Whoops. I meant Screen.SetResolution(Screen.resolutions[resolutionPointer].width,Screen.resolutions[resolutionPointer].height,true);

avatar image Madswint · Nov 21, 2013 at 04:36 PM 0
Share

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);

avatar image Madswint · Nov 21, 2013 at 05:05 PM 0
Share

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.

avatar image Professor Snake · Nov 21, 2013 at 05:17 PM 0
Share

$$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);

Show more comments
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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);
         }
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges