Unity3d Game timing Function implementation

Source: Internet
Author: User

Recently work is too busy, no way to seriously write a blog, but still have to take a good record of the daily study.

All kinds of games are heavily used in the timekeeping function, whether it is directly displayed in the front-end UI, or in the background run.

The time class is available in unity for easy access, and in the following example, I have a simple package that can be easily applied to various types of games.

1  Public classClockmanagement:monobehaviour {2 3     Private floatScreenWidth;4     Private floatScreenHeight;5     Private floattimescale;6      PublicGuiskin Clockguiskin;7      Public stringNowtime;8 9     voidStart ()Ten     { OneScreenWidth =Screen.width; AScreenHeight =Screen.height; -Nowtime ="0"; -Timescale =1; the     } -  -     voidOngui () -     { +Gui.skin =Clockguiskin; -Nowtime =timeformatbase (Mathf.floortoint (Time.time)); +Gui. Label (NewRect (screenwidth*0.9f, screenheight*0.05f, 120f, 30f), nowtime); A  at         if(GUI. Button (NewRect (Ten,Ten, -, -),"Pause")) -         { -Debug.Log ("Stop"); - Stop (); -         } -         if(GUI. Button (NewRect (Ten, -, -, -),"Acceleration")) in         { -Timescale = Mathf.clamp (timescale*2,0, -); to              + Settimescale (timescale); -Debug.Log ("Quick:"+timescale); the         } *     } $ Panax Notoginseng     stringTimechineseformat (floatntotaltime) -     { the         stringTime =string. Empty; +         floatDay = Mathf.floor (Ntotaltime/86400); A         floathour = Mathf.floor (ntotaltime%86400/3600); the         floatmin = Mathf.floor (ntotaltime%3600/ -); +         floatSEC = ntotaltime% -; -         if(Day >0) $Time =string. Concat (Day,"days"); $         if(hour>0) -Time =string. Concat (Time,hour,"when"); -         if(min>0) theTime =string. Concat (Time,min,"points"); -         if(sec>0)WuyiTime =string. Concat (Time,sec,"seconds"); the         returnTime ; -     } Wu  -     stringTimeformatbase (floatntotaltime) About     { $         stringTime =string. Empty; -         floathour = Mathf.floor (Ntotaltime/3600); -         floatmin = Mathf.floor (ntotaltime%3600/ -); -         floatSEC = ntotaltime% -; A         if(Hour >=0&& Hour <Ten) +Time =string. Concat ("0", Hour,":"); the         Else -Time =string. Concat (Hour,":"); $  the         if(Min >=0&& min <Ten) theTime =string. Concat (Time,"0", Min,":"); the         Else theTime =string. Concat (Time, Min,":"); -  in         if(Sec >=0&& sec <Ten) theTime =string. Concat (Time,"0", sec); the         Else AboutTime =string. Concat (Time, SEC); the         returnTime ; the     } the  +      Public voidSettimescale (floatScale ) -     { theTime.timescale =Scale ;Bayi     } the  the      Public voidStop () -     { -Time.timescale =0; the     } the}
Clock

Unity3d Game timing Function implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.