GameTime

From Unify Community Wiki
Jump to: navigation, search

GameTime

GameTime rotates a directional light to match the appropriate direction of the sun for the system time of day.

TODO: It doesn't change the length of the day for seasons nor the angle of the sun. It also doesn't turn off the light at night, as would be accurate.

Code

import System;
var date = DateTime.Now;
var timeDisplay : GUIText;
 
function Start() {
	InvokeRepeating("Increment", 1.0, 1.0);
}
function Update () {
	var seconds : float = date.TimeOfDay.Ticks / 10000000;
	transform.rotation = Quaternion.LookRotation(Vector3.up);
	transform.rotation *= Quaternion.AngleAxis(seconds/86400*360,Vector3.down);
	if (timeDisplay) timeDisplay.text = date.ToString("f");
}
 
function Increment() {
	date += TimeSpan(0,0,0, 1);
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox