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 WoflenGames · Nov 13, 2013 at 10:59 AM · screen

Custom settings not responding in game as should

Hey Guys,

I am trying to get these ingame Setting working,

The issue comes Revolving around the Fullscreen, The rest are working fine, Fullscreen doesnt save, everytime i start game up it goes back to Screen.fullScreen = false, Even when ini is set true;

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Text.RegularExpressions;
 
 public class Settings : MonoBehaviour {
     public static bool showMenu = false;
     private string settings;
     public static bool fullscreen;
     public string screenres = "1";
     public string curRes = "1";
     public string defaultx = "1024";
     public string defaulty = "768";
     int xx;
     int yy;
 
     public string[] ScreenRes;
     public Rect Box;
     public string selectedItem = "Select Sreen Resolution";
     bool editing = false;
 
     // Use this for initialization
 #if UNITY_STANDALONE_WIN
     void Start () {
         settings = System.IO.File.ReadAllText(@"settings.ini");
 
         string[] settingsLine = Regex.Split(settings, "\r\n");
         foreach (string line in settingsLine)
         {
             string[] thisLine = Regex.Split(line, "=");
             if(thisLine[0] == "fullscreen")
             {
                 if (thisLine[1] == "True" || thisLine[1] == "true")
                 {
                     Screen.fullScreen = true;
                 }
                 else
                 {
                     Screen.fullScreen = false;
                 }
             }else if(thisLine[0] == "ScreenRes")
             {
                 switch (thisLine[1])
                 {
                     case  "1":
                         Screen.SetResolution(1024,768,fullscreen);
                         break;
                     case "2":
                         Screen.SetResolution(1920, 1080, fullscreen);
                         break;
                 }
                 screenres = thisLine[1];
             }
         }
     
     }
     
     // Update is called once per frame
     void Update () {
         if (Screen.fullScreen != Settings.fullscreen)
         {
             Screen.fullScreen = Settings.fullscreen;
         }
     }
 
     void OnGUI()
     {
         if (showMenu == true)
         {
             GUI.Box(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 300), "");
             fullscreen = GUI.Toggle(new Rect(Screen.width / 2 - 150, Screen.height / 2 -150, 200, 30),fullscreen, "Fullscreen");
             /*if (GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 150, 150, 30), "Toggle FullScreen"))
             {
                 if (fullscreen == false)
                 {
                     fullscreen = true;
                 }else{
                     fullscreen = false;
                 }
                
             
             }*/
             GUI.Box(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 190, 150), "");
           
               
                 if (GUI.Button(new Rect(Screen.width/2 - 95,Screen.height/2-95,180,30),selectedItem))
                 {
                     editing = true;
                 }
 
                 if(editing)
                 {
                     Box.y = Screen.height / 2 - 85;
                     Box.width = 180;
                     for (int x = 0; x < ScreenRes.Length; x++)
                     {
                         if (GUI.Button(new Rect(Screen.width/2 -95 ,((Box.height * x) + Box.y + Box.height), Box.width, Box.height),ScreenRes[x]))
                         {
                             selectedItem = ScreenRes[x];
                             editing = false;
                         }
                     }
                 }
 
                 if (selectedItem == "1990x1080") 
                 {
                      xx = 1920 ;
                      yy = 1080 ;
                 }else if(selectedItem == "1024x768")
                 {
                     xx = 1024;
                     yy = 1080;
                 }
                
 
 
                 if (GUI.Button(new Rect(Screen.width / 2 - 60, Screen.height / 2 + 70, 120, 30), "Apply Screen"))
                 {
                     Screen.SetResolution(xx, yy, fullscreen);
                 }
             
             if(GUI.Button(new Rect(Screen.width/2-60,Screen.height/2+110,120,30),"Close"))
             {
                 showMenu = false;
                 saveSettings();
             }
 
         }
     }
 
     void saveSettings()
     {
         string output = "fullscreen=" + fullscreen;
         System.IO.StreamWriter file = new System.IO.StreamWriter(@"settings.ini");
         file.Write(output);
         file.Close();
     }
 #endif
 }
 
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 JohnnySunshine · Nov 13, 2013 at 12:13 PM

You never set the "fullscreen" variable, so it will always stay false. Set the variable when reading the settings file so it will be written correctly.

Comment
Add comment · Show 4 · 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 WoflenGames · Nov 13, 2013 at 01:08 PM 0
Share

i Have, Here is the variable - public static bool fullscreen;

avatar image JohnnySunshine · Nov 13, 2013 at 03:55 PM 0
Share

I mean you never assigned a value to it :) Write

 Settings.fullscreen = Screen.fullScreen;

after line 40

avatar image WoflenGames · Nov 13, 2013 at 03:56 PM 0
Share

I got this

  void Update () {
             if (Screen.fullScreen != Settings.fullscreen)
             {
                 Screen.fullScreen = Settings.fullscreen;
             }
         }
     
 
avatar image JohnnySunshine · Nov 13, 2013 at 04:04 PM 0
Share

I know, but you're writing SETTINGS.fullscreen into the file, and you never assign a value to it, so you're always writing 'false' into the file. In the update you set SCREEN.fullscreen, I meant the other way around! :)

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

17 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

STRANGE error with screen.height/screen.width 1 Answer

Cursor lock/unlock not working 1 Answer

How to engage an object if it's seen by my camera?? 1 Answer

touch position to world position 2D 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