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