There's a cautionary tale in this somewhere.
Don't assume that published code is correct or economical or even sensical.
This snippet came from a book (a CookBook of Unity3D code) published a couple of months ago ( and not cheap)
I've commented out the offending code and replaced the Update() method.
The code is meant to update text on a GUI overlayed over the game visuals. Every Update() method in every class script attached to every GameObject runs for every frame displayed ... that's about 15 <-> 80 frames per second. As you can imagine frugal code to get the job done is a benefit ; particularly when the Game screen gets busy ... lots of decisions need to be made to get that frame displayed "Am I dead" "Is this bling" "where are the zombies" "does the player want to turn here, speed up, slow down , jump, run away, fight, etc, etc"
It scares me a little that some peeps are going to just accept this code and use it in every game they build between now and when they get a 'real job'.
What concerns me more is that a similar situation is happening with AutoCAD plugin code.
Stay well and prosper !
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
public class ClockDigital : MonoBehaviour {
private Text textClock;
// Use this for initialization
void Start () {
textClock = GetComponent<Text>();
}
// Update is called once per frame ( nom 60 FPS. )
void Update () {
textClock.text = DateTime.Now.ToString("HH:mm:ss");
}
// Load of Crap !!
//void Update (){
// DateTime time = DateTime.Now;
// string hour = LeadingZero( time.Hour );
// string minute = LeadingZero( time.Minute );
// string second = LeadingZero( time.Second );
// textClock.text = hour + ":" + minute + ":" + second;
//}
//string LeadingZero (int n){
// return n.ToString().PadLeft(2, '0');
//}
}