Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 cindycharvet · Jun 16, 2021 at 03:21 AM · resolutionplayerprefssettingsdropdownresolution settings

How to save the resolution of screen between scenes

Hi, i'm doing the options menu for the game (the resolutions) and i now have all the code that i need but i don't know how to save it with the player prefs, basically I would like to save the resolution of the dropdown and the state of fullscreen between scenes. As now the code starts with a resolution but it doesn't save the selected resolution (the text of the dropdown options, the resolutions itself remains between scenes) or the state toggle of the fullscreen when I change from the main menu to the game scene.

using UnityEngine; using UnityEngine.UI;

public class setting_menu : MonoBehaviour

{ List widths = new List () {3840, 2560, 1920}; List heights = new List () {2160, 1440, 1080};

  void Awake()
  {
     SetResolution(1);
  }

  public void SetFullscreen(bool isFullscreen)
  {
      Screen.fullScreen = isFullscreen;
  }

  public void SetResolution(int resolutionIndex)
  {
     bool fullScreen = Screen.fullScreen;
     int width = widths[resolutionIndex];
     int height = heights[resolutionIndex];
     Screen.SetResolution(width, height, fullScreen);
  }

}

I did this following a tutorial on Youtube Thanks for the help!

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

2 Replies

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

Answer by Patrickmol · Jun 16, 2021 at 07:06 AM

 public static List widths = new List () {3840, 2560, 1920}; 
 public static List heights = new List () {2160, 1440, 1080};

with static you will be able to keep the value when changing scene

Comment
Add comment · Show 1 · 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 cindycharvet · Jun 16, 2021 at 02:47 PM 0
Share

Thanks for the help! Any idea of how to make the dropdown change the text of the option when I change the resolution? As now the code change the resolution and it stays between scenes but the dropdown options remains the same between scenes, I mean it doesn't change base on the resolution selected.

avatar image
1

Answer by unwshd_elend · Jun 16, 2021 at 07:28 AM

saving it with player prefs is not any different than saving other values , you simply define one key for width and one for height and save the values there , better than using static values since they only remain in current game session so it will something like this :

   private const string SCREEN_WIDTH = "sc_width";
   private const string SCREEN_HEIGHT = "sc_height";
 
    PlayerPrefs.SetInt(SCREEN_WIDTH , 3840);
 
    PlayerPrefs.SetInt(SCREEN_HEIGHT, 2160);
Comment
Add comment · Show 1 · 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 cindycharvet · Jun 16, 2021 at 02:47 PM 0
Share

Thanks for the help! Any idea of how to make the dropdown change the text of the option when I change the resolution? As now the code change the resolution and it stays between scenes but the dropdown options remains the same between scenes, I mean it doesn't change base on the resolution selected.

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

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

Related Questions

Ingame Quality Settings not recognized 1 Answer

Unity 5 not using my Resolution Settings 2 Answers

In Game Graphics/Resolution Options 2 Answers

Unity resolution dropdown duplicating 0 Answers

Resolution is not saving. 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