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 Damich123 · Jun 11, 2013 at 05:17 PM · guitexturetimefreeze

Change timescale to zero but still have GUI textures moving

I have created a collider that freezes the game, aka set the timescale to zero. When the timescale is zero, it freezes everything including my GUI texture that is supposed to be constantly running. Is there any way to exclude the GUI textures from the timescale change?

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 Damich123 · Jun 11, 2013 at 06:39 PM 0
Share
 static var meterCount : double = 1;
 var meter$$anonymous$$ax : double = 11.1;
 var meter$$anonymous$$in : double = 0.9;
 var countDown : boolean = false;
 
 var meter0 : Texture2D;
 var meter1 : Texture2D;
 var meter2 : Texture2D;
 var meter3 : Texture2D;
 var meter4 : Texture2D;
 var meter5 : Texture2D;
 var meter6 : Texture2D;
 var meter7 : Texture2D;
 var meter8 : Texture2D;
 var meter9 : Texture2D;
 var meter10 : Texture2D;
 
 function Update ()
 {
     var meterTexture = gameObject.Find("meter0");
     
     if(meterCount == 1)
     {
         meterTexture.guiTexture.texture = meter0;
     }
     if(meterCount == 2)
     {    
         meterTexture.guiTexture.texture = meter1;
     }
     if(meterCount == 3)
     {
         meterTexture.guiTexture.texture = meter2;
     }    
     if(meterCount == 4)
     {
         meterTexture.guiTexture.texture = meter3;
     }    
     if(meterCount == 5)
     {
         meterTexture.guiTexture.texture = meter4;
     }    
     if(meterCount == 6)
     {
         meterTexture.guiTexture.texture = meter5;
     }    
     if(meterCount == 7)
     {
         meterTexture.guiTexture.texture = meter6;
     }    
     if(meterCount == 8)
     {
         meterTexture.guiTexture.texture = meter7;
     }    
     if(meterCount == 9)
     {
         meterTexture.guiTexture.texture = meter8;
     }    
     if(meterCount == 10)
     {
         meterTexture.guiTexture.texture = meter9;
     }    
     if(meterCount == 11)
     {
         meterTexture.guiTexture.texture = meter10;
     }    
     
 }
 
 InvokeRepeating("Count",0,0.1);
 
 function Count()
 {    
     if ((meterCount < 12) && (countDown == true))
         meterCount -= 1;
         
     if ((meterCount > 0) && (countDown == false))
             meterCount += 1;    
                 
     if (meterCount == 11)
         countDown = true;
         
     if (meterCount == 1)
         countDown = false;
     
     if (meterCount > meter$$anonymous$$ax)
         meterCount = 11;
         
     if (meterCount < meter$$anonymous$$in)
         meterCount = 1;        
     
 }

1 Reply

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

Answer by robertbu · Jun 11, 2013 at 07:12 PM

When Time.timeScale is 0, Update() still gets called. InvokeRepeating() does not. So the trick would be to not use InvokeRepeating() and to use your own timer and use an alternate to Time.deltaTime to increment it if Time.timeScale is 0.

 #pragma strict
 static var meterCount : double = 1.0;
 var meterMax : double = 11.1;
 var meterMin : double = 0.9;
 var countDown : boolean = false;
 
  
 var meter0 : Texture2D;
 var meter1 : Texture2D;
 var meter2 : Texture2D;
 var meter3 : Texture2D;
 var meter4 : Texture2D;
 var meter5 : Texture2D;
 var meter6 : Texture2D;
 var meter7 : Texture2D;
 var meter8 : Texture2D;
 var meter9 : Texture2D;
 var meter10 : Texture2D;
 
 private var myDeltaTime : float;
 private var meterTexture : GameObject;
 private var myTimer = 0.0;
 
 
 function Start() {
     myDeltaTime = Time.deltaTime;
     meterTexture = gameObject.Find("meter0");
 }
  
 function Update ()
 {
     if (Time.timeScale > 0.01)
         myTimer += Time.deltaTime;
     else
         myTimer += myDeltaTime;
                 
     if (myTimer > 0.1) {
         Count();
         myTimer = 0.0;
     }
  
     if(meterCount == 1)
     {
        meterTexture.guiTexture.texture = meter0;
     }
     if(meterCount == 2)
     {  
        meterTexture.guiTexture.texture = meter1;
     }
     if(meterCount == 3)
     {
        meterTexture.guiTexture.texture = meter2;
     }  
     if(meterCount == 4)
     {
        meterTexture.guiTexture.texture = meter3;
     }  
     if(meterCount == 5)
     {
        meterTexture.guiTexture.texture = meter4;
     }  
     if(meterCount == 6)
     {
        meterTexture.guiTexture.texture = meter5;
     }  
     if(meterCount == 7)
     {
        meterTexture.guiTexture.texture = meter6;
     }  
     if(meterCount == 8)
     {
        meterTexture.guiTexture.texture = meter7;
     }  
     if(meterCount == 9)
     {
        meterTexture.guiTexture.texture = meter8;
     }  
     if(meterCount == 10)
     {
        meterTexture.guiTexture.texture = meter9;
     }  
     if(meterCount == 11)
     {
        meterTexture.guiTexture.texture = meter10;
     }  
  
 }
  
  
 function Count()
 {   
     if ((meterCount < 12) && (countDown == true))
        meterCount -= 1;
  
     if ((meterCount > 0) && (countDown == false))
          meterCount += 1; 
  
     if (meterCount == 11)
        countDown = true;
  
     if (meterCount == 1)
        countDown = false;
  
     if (meterCount > meterMax)
        meterCount = 11;
  
     if (meterCount < meterMin)
        meterCount = 1;     
  
 }

Note the code above assumes that Time.timeScale is not zero when this script is started. Also it uses a single sample of deltaTime which could be a bit high or low on average.

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 Damich123 · Jun 11, 2013 at 07:38 PM 0
Share

Thank you, works perfect! Good to know that InvokeRepeating is affected by time scale.

avatar image robertbu · Jun 11, 2013 at 09:42 PM 0
Share

If this answered your question, can you click on the checkmark next to the answer to close it out. Thanks.

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

14 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

Related Questions

Can you change time scale to zero but still have GUI textures changing? 2 Answers

How to save screenshot then use it as a gui texture? 2 Answers

Why are all my GUITexture elements semi-transparent? 0 Answers

Rotate Texture 1 Answer

Problem With GUI Circle Thickness 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