UnityGame/Assets/Scripts/DayNightCycle.cs
2024-10-27 10:53:47 +03:00

22 lines
604 B
C#

using UnityEngine;
public class DayNightCycle : MonoBehaviour
{
public Light sun;
public float dayDuration = 120f; // Äëèòåëüíîñòü äíÿ â ñåêóíäàõ
private float currentTime = 0f;
void Update()
{
currentTime += Time.deltaTime;
float timePercentage = currentTime / dayDuration;
float sunAngle = Mathf.Lerp(0, 360, timePercentage);
sun.transform.rotation = Quaternion.Euler(new Vector3(sunAngle - 90, 170, 0));
// Ñáðîñ âðåìåíè ïîñëå ïîëíîãî öèêëà
if (currentTime >= dayDuration)
{
currentTime = 0f;
}
}
}