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 Inan · May 17, 2011 at 07:34 PM · timercountdownsecondsminutes

Countdown Timer Help About putting 0's

Hello everyone, here is my countdown code :

var seconds =60; var a =0; var minutes = 14; var b = 0;

function Awake(){ a=1; }

function Update() {

GameObject.Find("Seconds").guiText.text =""+seconds; // says GUI TEXT called Seconds to put seconds on GameObject.Find("Minutes").guiText.text =""+minutes; // says GUI TEXT called Minutes to put minutes on

if(b==1) { CountdownMinutes(); }

if(a==1){ CountdownSeconds(); }

if(seconds == 0){ b = 1; } else { b=0; }

function CountdownSeconds(){ a=0; yield WaitForSeconds(1); seconds-=1; a=1; }

function CountdownMinutes() { b=0; minutes -=1; seconds = 60;

}

}

This is working quite well, but like this , there is 2 Gui text on the screen and starts like this :

14:59 like i wanted, but when the seconds get under 10, it's being like this:

14:5

but i want it to be like this 14:05 , i mean if it's under 10 i want it to put 0 near it,same thing for the minutes.

Any idea about doing this ?

Thanks.

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 · May 17, 2011 at 08:04 PM

You should be able to use seconds.ToString("00") to pad it to two numbers

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 Inan · May 17, 2011 at 08:10 PM 0
Share

in where ,

GameObject.Find("Seconds").guiText.text =""+seconds;

here ?

avatar image Inan · May 17, 2011 at 08:28 PM 0
Share

ok , i did it, it works thank you very much :)

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

How to stop a Countdown Timer? 1 Answer

CountDown Timer Help (Seconds problem) 2 Answers

Turn seconds into minutes and seconds MM:SS 1 Answer

Format String Minutes:Seconds 3 Answers

Making a timer 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