Skip to content

Instantly share code, notes, and snippets.

@keiranlovett
Created September 27, 2013 18:03
Show Gist options
  • Save keiranlovett/6732564 to your computer and use it in GitHub Desktop.
Save keiranlovett/6732564 to your computer and use it in GitHub Desktop.
GameTime rotates a directional light to match the appropriate direction of the sun for the system time of day.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment