Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Tyler_Miller · May 06, 2016 at 04:10 PM · guitimescore

Does GUI update every time a scene is loaded?

I am attempting to make my first game in Unity so I am very new to the process. Its a basic game based on the time it takes you to complete a level. I have a scene that loads after the player has completed the level which tells you your time and if you have beat the best time or not. I noticed after playing through one time then attempting to play through again, the GUI for "your time" only displays the last time you played through and not the current. Not sure if its my code or logic error, but its an important part of the game and can't figure it out! This is the code attached to an object in my "level one win game scene"....

using UnityEngine; using System.Collections; public class Lvl1_WinGame : MonoBehaviour { %|-268258433_1|% %|618304092_2|% private int seconds = (playTime % 60); %|-1959320627_4|% %|1587356682_5|% %|952064105_6|% %|-1404413236_7|% %|-816941512_9|% %|1611647783_10|% GUI.color = Color.black; %|-1444865868_12|% %|-1195048236_13|% %|593022224_14|% %|-2127596018_15|% %|-1085200602_16|% %|875474438_17|% %|-1404530180_18|% %|-1783748057_19|% else if (minutes == minutes2 && seconds == seconds2) %|-1739097657_21|% %|-466144641_22|% %|1662746052_23|% %|922373008_25|% %|-82144881_26|% GUI.Label (new Rect ((Screen.width/2)-195,(Screen.height/2)+80, 400, 50), "You didnt beat the best time..."); %|-1911277770_28|% %|-1809811350_30|% %|-2122394016_31|% %|503576203_32|% }

This is my first question on unity forums so i'm not sure what other information to provide, let me know if there is anything else that I can provide. Any help would be appreciated!

Comment
Add comment · Show 1
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 Tyler_Miller · May 06, 2016 at 04:16 PM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class Lvl1_WinGame : $$anonymous$$onoBehaviour 
 {
     public static int playTime = Timer.playTime;
     private int $$anonymous$$utes = (playTime / 60) % 60;
     private int seconds = (playTime % 60);
     private int $$anonymous$$utes2;
     private int seconds2;
     private int textSize = 20;
     public Font font;
 
 
     
     void OnGUI()
     {    
         GUI.color = Color.black;
         GUI.Label (new Rect ((Screen.width/2)-195,Screen.height/2, 400, 50), "Your Time = " + $$anonymous$$utes.ToString() + " $$anonymous$$inutes " + seconds.ToString() + " Seconds ");
         GUI.Label (new Rect ((Screen.width/2)-195,(Screen.height/2)+40, 400, 50), "Best Time = " + $$anonymous$$utes2 + " $$anonymous$$inutes " + seconds2 + " Seconds ");
         
         if (($$anonymous$$utes < $$anonymous$$utes2 && seconds < seconds2) || ($$anonymous$$utes == $$anonymous$$utes2 && seconds < seconds2) || ($$anonymous$$utes < $$anonymous$$utes2 && seconds > seconds2))
         {
             GUI.Label (new Rect ((Screen.width/2)-195,(Screen.height/2)+80, 400, 50), "You beat the best time!");
         } 
         
         else if ($$anonymous$$utes == $$anonymous$$utes2 && seconds == seconds2) 
         {
             GUI.Label (new Rect ((Screen.width/2)-195,(Screen.height/2)+80, 400, 50), "You tied the best time!");
         } 
         
         else if (($$anonymous$$utes > $$anonymous$$utes2 && seconds > seconds2) || ($$anonymous$$utes==$$anonymous$$utes2 && seconds>seconds2))
         {
             GUI.Label (new Rect ((Screen.width/2)-195,(Screen.height/2)+80, 400, 50), "You didnt beat the best time...");
         }
         
         GUI.skin.label.fontSize = textSize;
         GUI.skin.label.font = font;
     }
 
     
 }

1 Reply

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

Answer by Nazirzadeh · May 06, 2016 at 04:22 PM

It does not change because your playTime is static!
playTime should not be static.

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 Tyler_Miller · May 06, 2016 at 04:32 PM 0
Share

Ohhh okay thank you, yeah that makes since. But now I'm not sure how to do the initialization of "$$anonymous$$utes" and "seconds", because its saying a field initializer cannot reference a non static field. Should I initialize them in Start()?

avatar image Tyler_Miller · May 06, 2016 at 04:39 PM 0
Share

Got it working, thanks! you're a hero

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

77 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

Related Questions

Looking for a simple Score Multiplier. 1 Answer

How to reset GUI score after falling down? 4 Answers

How do I add my Timer to my Score system in C# ? 0 Answers

Increase the time in X seconds each time the score equals a multiple of 500 1 Answer

How do I fix the following error? 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