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 MikezNesh · Jun 28, 2010 at 02:13 PM · texttimervalue

Timer and TextMesh issue....

I have a TextMesh that has the time of the Timer. My starting time is 63. But I want the TextMesh to display 60 if the TIme is greater then 60 for a special reason.

I tried to do this:

if( timeLeft > 60) {

textMesh = GameObject.Find("Timer").GetComponent(TextMesh);

textMesh.text = 60;

}

But it didn't work...

How can I do this?

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
1
Best Answer

Answer by Mike 3 · Jun 28, 2010 at 03:29 PM

assuming textMesh is declared as var textMesh : TextMesh; somewhere and not just var textMesh; you just need to change your code to

textMesh.text = "60";

Alternatively, just clamp the value when you're displaying it (without the if timeLeft > 60 conditional):

var timeLeftClamped : int = Mathf.Clamp(timeLeft, 0, 60);
textMesh.text = timeLeftClamped.ToString();
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 MikezNesh · Jun 29, 2010 at 12:54 AM 0
Share

A problem... that would change timeLeft to 60. I just want to display 60 in the text but timeLeft still stays the same. Like if the timeLeft is 63 display 60 int the text but leave the timeLeft alone.

avatar image Mike 3 · Jun 29, 2010 at 01:16 AM 0
Share

No, that's what the timeLeftClamped variable is for

avatar image MikezNesh · Jun 29, 2010 at 08:34 AM 0
Share

Now with the clamp my timer goes to negatives...

avatar image Mike 3 · Jun 29, 2010 at 10:17 AM 0
Share

changed the code

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

No one has followed this question yet.

Related Questions

Changing GUItext value 1 Answer

Reading integer value from specified character(s) on text line? 2 Answers

Want my UI to not move when I move my camera? 2 Answers

how to reset timer when score hits an increment of 50 1 Answer

How to set text(timer) to a fixed place 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