Im trying to make a daylight system that works off of a clock in my hud, so whenever i change the “game time” the sun/moonlight will react accordingly. I plan on having multiple lights set up in my scene as part of the rig, so i’ve decided to use a military time structure, and say time=2300, then i can make sure street lights are on, the main sun’s rotating in the right direction, etc. i believe i’m on the right track, but I am pretty new at coding, so here’s what i’ve come up with (be gentle
)
//====================================//
//
// Daylight System
// (c)2010 Bill Hayes
//
//====================================//
// Variable Declarations ===============//
var sun : Light;
var timeofday : float;
var azimuth : int;
var elevation : int;
var brightscale : float;
//Function Declarations =================//
function IncrementTime()
{
timeofday+=99;
}
//=====================================//
function Update ()
{
//=====================================//
if (Input.GetKeyUp("e"))
{
IncrementTime();
}
//=======================================//
var lightRotation;
switch(timeofday)
{
case 0:
lightRotation = Vector3 (0, 0, 0);
sun.transform.Rotate (lightRotation);
//timeofday++;
break;
case 100:
sun.transform.Rotate (1,0,0);
break;
case 200:
sun.transform.Rotate (1,0,0);
break;
case 300:
sun.transform.Rotate (1,0,0);
break;
case 400:
sun.transform.Rotate (1,0,0);
break;
case 500:
sun.transform.Rotate (1,0,0);
break;
case 600:
sun.transform.Rotate (1,0,0);
break;
case 700:
sun.transform.Rotate (1,0,0);
break;
case 800:
sun.transform.Rotate (1,0,0);
break;
case 900:
sun.transform.Rotate (1,0,0);
break;
case 1000:
sun.transform.Rotate (1,0,0);
break;
case 1100:
sun.transform.Rotate (1,0,0);
break;
case 1200:
lightRotation = Vector3 (90, 0, 0);
sun.transform.Rotate (lightRotation);
timeofday++;
break;
case 1300:
sun.transform.Rotate (1,0,0);
break;
case 1400:
sun.transform.Rotate (1,0,0);
break;
case 1500:
sun.transform.Rotate (1,0,0);
break;
case 1600:
sun.transform.Rotate (1,0,0);
break;
case 1700:
sun.transform.Rotate (1,0,0);
break;
case 1800:
sun.transform.Rotate (1,0,0);
break;
case 1900:
sun.transform.Rotate (1,0,0);
break;
case 2000:
sun.transform.Rotate (1,0,0);
break;
case 2100:
sun.transform.Rotate (1,0,0);
break;
case 2200:
sun.transform.Rotate (1,0,0);
break;
case 2300:
sun.transform.Rotate (1,0,0);
break;
}
}
now I don’t mind having to hard code all 24 hours of the day, as opposed to having an automatically scripted rotation, cuz time will pass by the hour in the game as you complete activities. My problem here is rotating directional lights. You can see in case 1200 i have the light rotating 90 degrees on it’s X axis, when in fact i need to set it’s rotation to 90. How can i do this, i tried all the methods in the script reference like eulerAngles, and localEulerAngles, but i still can’t get it. any suggestions?