22 lines
604 B
C#
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;
|
|
}
|
|
}
|
|
} |