Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 dandelo99 · Apr 20, 2016 at 10:53 AM · timer-scriptclock

How can i Set my Clock

I use this script in 3d Text it works, but i want to set clock for example it'll starts at 00:00:00 how can i do this ? this is the my script thanks a lot.

 var date : System.DateTime;
   
  //sets something allowing you to populate it with the date and time
  private var text : String;
   
   
  function Update()
  {
      //tells the var to look for the precise moment you are at
      var date = System.DateTime.Now;
      //converts the above var to a readable string
      text = date.ToString("HH:mm:ss");
      //prints it to inspector
       GetComponent(TextMesh).text = text; 
  }
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 jgodfrey · Apr 20, 2016 at 06:45 PM -1
Share

Set what clock? That actual system clock? Or, some in-game "clock"?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jessespike · Apr 20, 2016 at 07:42 PM

Store a "start time" and subtract it from the "current time", this will give you a timespan of the elapsed time. Call the Reset function to start back at 00:00:00.

 var date : System.DateTime;
 
 //sets something allowing you to populate it with the date and time
 private var text : String;
 
 var startDateTime : System.DateTime;
       
 function Start()
 {
     Reset();
 }
         
 public function Reset()
 {
     startDateTime = System.DateTime.Now;
 }
        
 function Update()
 {
     //tells the var to look for the precise moment you are at
     var date = System.DateTime.Now;
 
     //converts the above var to a readable string
     //text = date.ToString("HH:mm:ss");
 
     // calculate the timespan between the start time and current time
     var timespan : System.TimeSpan = date - startDateTime;
     text = String.Format("{0}:{1}:{2}",
         timespan.Hours.ToString("00"),
         timespan.Minutes.ToString("00"),
         timespan.Seconds.ToString("00"));
 
     //prints it to inspector
     GetComponent(TextMesh).text = text; 
 }
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

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

42 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 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 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

Clock Script From Java to C# Help 1 Answer

How Would I Change This To Read Within A Time Range? 1 Answer

Minutes and Seconds in a text 1 Answer

Javascript beginner here: how do I implement time such as hours and days? 2 Answers

How do I make my timer continue to count? (C# Script) 2 Answers


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