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 mikez69 · Oct 29, 2011 at 02:00 AM · timerdeltatime

Use timer to remove text

I am trying to get timer to remove GUI text... I have gotten this far and most of it works but I cannot get the timer to actually count down and remove text.

static var textOn : boolean = false; static var textContent : String;

private var textTimer:float ;

function Start() {

 textTimer = 0.0;    
 textOn = false;
 
 guiText.text = "";
 

}

function Update () {

 if(textOn)
 {
     guiText.enabled = true;
     guiText.text = textContent;
     
     
         var textTimer:float -= 1 * Time.deltaTime;
     
 }
 
 var textTimer:float = 6.0;
 
 if(textTimer >= 5.0 )
 {
     textOn = false;
     guiText.enabled = false;
     textTimer = 0.0;
     
     
 }
 

}

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
2

Answer by Rod-Green · Oct 29, 2011 at 02:58 AM

Seems like you might have some local vs global property issues (scope) as well as others.

try this ( I don't use JS so there might be some issue)

 var startTimer:float = 0.0;
 var textOffTime:float = 6.0;
 
 
 function OnEnable() {
 
     startTimer = Time.time;
 
     textOn = true;
 
     guiText.text = "";
 
 }
 
 function Update () {
 
     if(textOn)
     {
         guiText.enabled = true;
         guiText.text = textContent;
 
     }
 
     if(Time.time - startTimer >= textOffTime )
     {
         textOn = false;
         guiText.enabled = false;
 
 
 
     }
 }
Comment
Add comment · 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
0

Answer by mikez69 · Oct 29, 2011 at 03:47 PM

Actually it was this line:

 var textTimer:float -= 1 * Time.deltaTime;

It should actually read:

 var textTimer += Time.deltaTime;

Took a bunch of trial and error but I figured it out. Thanks for the attempt though!

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 Rod-Green · Oct 31, 2011 at 11:06 PM 0
Share

I can't see how that code can possibly work..

    if(textOn)
    {
           guiText.enabled = true;
           guiText.text = textContent;


           var textTimer:float -= 1 * Time.deltaTime;

    }

    // textTimer is always 6.0 at this point
    var textTimer:float = 6.0; 

    if(textTimer >= 5.0 ) // This is ALWAYS true
    {
           textOn = false;
           guiText.enabled = false;
           textTimer = 0.0;


    }

Therefore any calculation done in the (if(textOn)) section is reverted by the next line "var textTimer:float = 6.0" So I guess you must have fixed that issue also.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Accurate timing while using timeScale. 1 Answer

Certain timers run too fast 1 Answer

Timer limits 0 Answers

Total Time Played since Installation 2 Answers

Why will this timer not count down? 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