I’m got a game object that has it’s z-axis rotated to a new position when the scene starts, based on the time of day. I want the color of the game object to change depending on how many degrees the object’s z-axis rotation is at. The if statements are failing because the value I’m getting returned is less than 1.0, but the rotation in the editor says it’s like 221 degrees.
What am I missing here?
note this isn’t the whole script, I didn’t copy over anything not related to this issue.
The IF statements in the getSunState() always execute the first one because the results of this.transform.rotation.z always com in below “1”.
//Lerp colors of sun to simulate sunrise
function sunRise(){
Debug.Log("sunRise called 3");
sun.color = Color.Lerp (sunNightColor, sunDayColor, Time.deltaTime * 21600);
}
//Lerp colors of sun to simulate sunset
function sunSet(){
Debug.Log("sunSet called 3");
sun.color = Color.Lerp (sunDayColor, sunNightColor, Time.deltaTime * 28800);
}
function getSunState() {
Debug.Log("getSetState called 2");
Debug.Log("transform.rotation.z = " + transform.rotation.z);
while (normalPassageOfTime == true) {
if (transform.rotation.z > 75 && transform.rotation.z < 120) {
sunRise();
}
if (this.transform.rotation.z >= 120 && this.transform.rotation.z < 240) {
sun.color = sunDayColor;
Debug.Log("Sun color set to Day 3");
}
if (this.transform.rotation.z >= 240 && this.transform.rotation.z < 285) {
sunSet();
}
if (this.transform.rotation.z >= 165 || this.transform.rotation.z <= 75) {
sun.color = sunNightColor;
}
yield;
}
}
//set position of the sun based on time of day
function setSun() {
Debug.Log("setSun function works 1");
transform.Rotate(0,0,degreesOfRotation * (hoursInSeconds + minutesInSeconds));
getSunState();
Debug.Log("z rotation = " + this.transform.rotation.z);
Debug.Log("sunRise called 3");
}
//rotate the sun based on set speed
function moveSun() {
while (speedOfLight > 0) {
//Multiplies speed variable by number of degrees to rotate per second
speedModifier = degreesOfRotation * speedOfLight;
transform.Rotate(0,0,speedModifier * Time.deltaTime);
yield;
}
}
function Start () {
normalPassageOfTimeToggle();
importVariables();
if (normalPassageOfTime == true) {
setClockHour();
transform.rotation = Quaternion.identity;
setSun();
moveSun();
}
//Debug.Log("TODPhrase within Start function is " + timeOfDayPhrase);
//Debug.Log("clockHour within Start function is " + clockHour);
}