// Update is called once per frame void Update() { Time midday = clock.GetMiddayTime(); currentTime = clock.getCurrentTime(); if (previousTime.CompareTo(midday) < 0 && currentTime.CompareTo(midday) >= 0) { if (debug) { Debug.Log("MOONPHASES: midday reached"); Debug.Break(); } daysSincePhaseChange++; if (daysSincePhaseChange > phaseLengths[phaseIndex]) { changePhase(); } } previousTime = currentTime.Clone(); }
void Update() { currentTime = clock.getCurrentTime(); Time sunset = clock.getSunsetTime(); Time sunrise = clock.getSunriseTime(); Time midday = clock.GetMiddayTime(); //SUN AND MOON ROTATION AROUND THE TERRAIN //check if sunset has been reached if (daytime && currentTime.CompareTo(sunset) >= 0) { if (debug) { Debug.Log("REACHED SUNSET -------------------------"); } daytime = false; int timePased = previousTime.SecondsBetween(sunset); float rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": applying rotation to get to sunset position: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); previousTime = sunset.Clone(); //new rotation speed: if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": --Calculating new rotation speed: -------------- "); } Time start = sunset.Clone(); Time end = clock.getNextSunriseTime(); int secondsBetweenPhases = start.SecondsBetween(end); if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": start: " + start.ToString() + "\t end: " + end.ToString() + "\n" + "Seconds between them: " + secondsBetweenPhases); } rotationSpeed = 180.0f / secondsBetweenPhases; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": new rotationspeed: " + rotationSpeed); Debug.Break(); } //esta parte esta aqui solo para depurar y no llenar la pantalla de mensajes en cada update, pero a la larga hay que quitarlo if (previousTime != currentTime) { if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": Completar la rotacion desde atardecer a currentTime"); } timePased = previousTime.SecondsBetween(currentTime); rotationAngle = rotationSpeed * timePased; transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); } } //check if sunrise has been reached if (!daytime && currentTime.CompareTo(sunrise) >= 0 && currentTime.CompareTo(sunset) < 0) { if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": REACHED SUNRISE --------------------------"); Debug.Break(); } daytime = true; int timePased = previousTime.SecondsBetween(sunrise); float rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": applying rotation to get to sunrise position: " + rotationAngle); Debug.Break(); } transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); previousTime = sunrise.Clone(); //new rotation speed: if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": --Calculating new rotation speed: -------------- "); } Time start = sunrise.Clone(); Time end = clock.getNextSunsetTime(); int secondsBetweenPhases = start.SecondsBetween(end); if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": start: " + start.ToString() + "\t end: " + end.ToString() + "\n" + "Seconds between them: " + secondsBetweenPhases); } rotationSpeed = 180.0f / secondsBetweenPhases; timePased = sunrise.SecondsBetween(currentTime); rotationAngle = rotationSpeed * timePased; if (debug) { Debug.Log("SUN/MOON ROTATION" + this.name + ": new rotationspeed: " + rotationSpeed); Debug.Break(); } } if (previousTime != currentTime) { int timePased = previousTime.SecondsBetween(currentTime); float rotationAngle = rotationSpeed * timePased; transform.RotateAround(Vector3.zero, Vector3.right, rotationAngle); } previousTime = currentTime.Clone(); }