- Home /
Question by
rOBY GAMES · May 24, 2014 at 10:42 PM ·
charactertimeclock
Digital clock
Hello.
I would like a digital clock for my character. When I want to see what time my character raises his arm with showing the time. I would like to put this script in 3D Text, so you can see the time. This script can not I add gui.label to insert text in 3d. Some Suggested?
The script that I want to use:
var date : System.DateTime;
//sets something allowing you to populate it with the date and time
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
print (text);
}
Comment
Best Answer
Answer by robertbu · May 25, 2014 at 01:19 AM
Create a 3D text object (GameObject > Create Other > 3D Text). Attach this script (your script with just a couple of changes):
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;
}
For a watch, you will need to change the shader:
http://wiki.unity3d.com/index.php?title=3DText
In addition, you might want to update the text in a function called by InvokeRepeating() four times per second rather than do it every frame in Update().
Thanks Robertbu. It all works perfectly. Thank you! :-)