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 bionicnacho · Jan 28, 2013 at 01:04 AM · resolutiontogglefullscreenfull screenresolution dialog

Setting Resolutions in game/checking windowed mode

Hey!

So, basically i have a button that lets you go from full screen to windowed, in game.

Problem is that when you go to full screen, the windowed resolution still carries on.

What i want to do is let the user, in a dialog box IN GAME, select from the list of their supported resolutions a WINDOWED mode resolution and another for FULLSCREEN.

How would i go about doing this?

I was trying to do something like this... #pragma strict

 var resolutions : Resolution[];
 static var selectedFULLres : int;
 static var selectedWINres : int;
 private var isfullscreen : boolean;
 
 function Start()
 {
     resolutions = Screen.resolutions;
         for (var res in resolutions) {
         print(res.width + "x" + res.height);
     }
 }
 
 function toggleFS()
 {
     if(!isfullscreen)
     {
         Screen.SetResolution (resolutions[selectedFULLres].width, resolutions[selectedFULLres].height, true);
         isfullscreen = true;
     }
     if(isfullscreen)
     {
         Screen.SetResolution (resolutions[selectedWINres].width, resolutions[selectedWINres].height, false);
         isfullscreen = false;
     }
 }

The problem is that... 1. How can i see if the user is in fullscreen or not? I want to get UNITY's answer (like if they had chosen windowed on the launcher) 2. How would i have a list of resolutions, in a visible way, so that the user could click on the desired resolution for each mode?

Also, would i be able to do it this way?

All help is appreciated.

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 GusdudeTyr · Jan 09, 2014 at 03:16 AM

I have been treating with similar issues, here is an example code that covers your question, Screen.fullScreen returns true if you're on fullscreen mode, false if you're on windowed mode. Create a new monobehaiour class, paste this code and test it.

 using UnityEngine;
 using System.Collections;
 
 public class ResolutionSelection : MonoBehaviour {
 
     string showResolution; //Text that will hold the chosen resolution
     Resolution[] resolutions;//Variable that holds the different resolutions available
     int myResolutionIndex = 0; //Used as the index to scroll between resolution values
 
     void Start () {
         //Screen.resolutions takes the supported fullscreen resolution values of the monitor
         resolutions = Screen.resolutions;    
     }
     
     void Update () {
     
     }
 
     void OnGUI() {
         GUILayout.BeginArea(new Rect((Screen.width / 2) - (Screen.width / 4), Screen.height / 2 - (Screen.height / 4), Screen.width / 2, Screen.height / 2));
 
         GUILayout.BeginHorizontal();
         GUILayout.Label("RESOLUTION");
         GUILayout.FlexibleSpace();
         if (GUILayout.Button("<")) { showResolution = toggleResolutions(false); }
         GUILayout.Label(showResolution);
         if (GUILayout.Button(">")) { showResolution = toggleResolutions(true); }
         GUILayout.EndHorizontal();
 
         GUILayout.BeginHorizontal();
         //Take the value of fullscreen from the Screen class. (This can be used to SET the value too)
         GUILayout.Label("Is the game in fullscreen?: " + Screen.fullScreen.ToString()); 
         GUILayout.EndHorizontal();
 
         GUILayout.EndArea();
     }
 
     //This function 'scrols' between the different resolution values
     private string toggleResolutions(bool direction)
     {
         if (direction)//If direction = true, the right arrow button was pressed
         {
             myResolutionIndex++;
             if (myResolutionIndex >= resolutions.Length)
             {
                 myResolutionIndex = 0;
             }
         }
         else if (!direction)//If false, the left button was pressed
         {
             myResolutionIndex--;
             if (myResolutionIndex < 0)
             {
                 myResolutionIndex = resolutions.Length - 1;
             }
         }
         //Returns the next or previous value of resolution in the array
         return resolutions[myResolutionIndex].width + " x " + resolutions[myResolutionIndex].height;
     }
 }
 
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

10 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

Related Questions

Screen.SetResolution doesn't work when the game starts windowed? 0 Answers

Unity Player Crashes ONLY on Firefox after migration 0 Answers

Is it possible to change between exclusive fullscreen and borderless fullscreen in-game? 2 Answers

How do I force a Unity executable to start on a secondary monitor? 0 Answers

Lighting is wrong unless native resolution is used 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