• 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 joshmann971 · May 15, 2014 at 10:25 PM · guibuttonresolution

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by VesuvianPrime · May 15, 2014 at 11:05 PM

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);
 }
Comment
Add comment · Show 2 · 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 joshmann971 · May 17, 2014 at 07:12 PM 0
Share

thanks bud, i will definitely use this

avatar image joshmann971 · May 17, 2014 at 07:15 PM 0
Share

wait, this looks like C#, not java

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 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 avatar image avatar image

Related Questions

Using GUI Button to activate script instances 1 Answer

How do I Scale a GUITexture or GUIText for different resolutions screen sizes on the iPhone? 1 Answer

C# Why Won't My GUI Layout Button Appear? 1 Answer

Unity GUI multiple grids? 0 Answers

controlling GUI.Button state 1 Answer


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