Untitled
unknown
plain_text
a year ago
580 B
7
Indexable
public Light sun; // The light that acts as the sun
public float dayDuration = 120f; // Time for a full day in seconds
private float time = 0f; // Track time of day
void Update()
{
// Increase time based on day duration and loop back to 0 after a full day
time += Time.deltaTime / dayDuration;
if (time > 1f) time = 0f; // Reset time after a full day
// Rotate the sun on the x-axis only, to simulate the day and night
float rotationAngle = time * 360f - 90f;
sun.transform.rotation = Quaternion.Euler(rotationAngle, 0f, 0f);
}Editor is loading...
Leave a Comment