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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Alp-Giray-Savrum · Sep 09, 2013 at 02:19 PM · timestaticvaluetimer-scriptstatic variables

Static Variable Doesn't Change ?

Hello Unity Community. I'm very anixous about a code :S There's a code i translate form C# to .js

 #pragma strict
 
         ///////////////////////////////////////////////////////////
         
             var    startTime : float;
         
             var restSeconds : float;
         
             var roundedRestSeconds : int;
         
             var displaySeconds : float;
         
             var displayMinutes : float;
         
             var timeLeft : float;                    
                                                                 
             static var countDownSeconds : int = 15;                    
             
             var timeText : String;
                                                                                                     
         ///////////////////////////////////////////////////////////        
         
         function Start() 
         
         {        
             startTime = Time.deltaTime;                            
         }
         
         ///////////////////////////////////////////////////////////
         
         function OnGUI () 
         
         {
         
                 timeLeft = Time.time - startTime;
                 
                 restSeconds = countDownSeconds - (timeLeft);
                 
                 roundedRestSeconds = Mathf.CeilToInt(restSeconds);
                 
                 displaySeconds = roundedRestSeconds % 60;
                 
                 displayMinutes = (roundedRestSeconds / 60) %60;
         
                 timeText = (displayMinutes.ToString() + ":");
                 
                 ///////////////////////////////////////////////////////////
                 
                 if (displaySeconds > 9)
                 {
                 
                     timeText = timeText + displaySeconds.ToString();
                 
                 }
                 else
                 {    
                 
                     timeText = timeText + "0" + displaySeconds.ToString();
                 
                 }
                 
                 var textMesh : TextMesh = gameObject.GetComponent(TextMesh);
                 
                 textMesh.text = timeText.ToString();
                 
                 
                 
         }

everthing is fine with code but I've assigned 2 more codes from outside.

First one is ;

 #pragma strict
 
     
     var gameOver : GameObject;
     
     
 
     function Start () {
 
         yield WaitForSeconds(15);
     
         Time.timeScale = 0;
         
         gameOver.active = true;
         
     }

wait 15 seconds than stop whole game time. so it works fine too.

but when i try to reset counter time with this code ;

 #pragma strict
 
 var isSaveDucks = false ;
 
 
 
 var GameOver : GameObject;
 
 
 function OnMouseDown()
 {
 
 if (isSaveDucks) {
 
     Application.LoadLevel(2);
 }
 
 if(!isSaveDucks) {
     
     CountPoints.Score = 0;
     
     Timer.countDownSeconds = 15;
     
     Application.LoadLevel(Application.loadedLevel);
     
     Time.timeScale = 1;
         
 }
 
 }

It does'nt work :( I must do this so please help me ! I'm Stuck.

(P.S. I'm 14 years old sorry for my bad english :/ )

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 Alp-Giray-Savrum · Sep 09, 2013 at 02:20 PM 0
Share

The original C# code is this :

     public class TimerScript : $$anonymous$$onoBehaviour {
     private float startTime;
     private float restSeconds;
     private int roundedRestSeconds;
     private float displaySeconds;
     private float display$$anonymous$$inutes;
     public int CountDownSeconds=120;
     private float Timeleft;
     string timetext;
      
      
     // Use this for initialization
      
     void Start ()
     {
     startTime=Time.deltaTime;
      
     }
      
     void OnGUI()
     {
      
     Timeleft= Time.time-startTime;
      
     restSeconds = CountDownSeconds-(Timeleft);
      
     roundedRestSeconds=$$anonymous$$athf.CeilToInt(restSeconds);
     displaySeconds = roundedRestSeconds % 60;
     display$$anonymous$$inutes = (roundedRestSeconds / 60)%60;
      
     timetext = (display$$anonymous$$inutes.ToString()+":");
     if (displaySeconds > 9)
     {
     timetext = timetext + displaySeconds.ToString();
     }
     else
     {
     timetext = timetext + "0" + displaySeconds.ToString();
     }
     GUI.Label(new Rect(650.0f, 0.0f, 100.0f, 75.0f), timetext);
     }}`

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

recharging value? 0 Answers

How do I stop 'timeSinceLevelLoad' without pausing entire game? 2 Answers

Timer ends game 1 Answer

how to keep static variables or 2d array value 0 Answers

How Would I Change This To Read Within A Time Range? 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