UnityGame/Assets/Scripts/DayNightCycle.cs

22 lines
604 B
C#
Raw Normal View History

2024-10-27 10:53:47 +03:00
using UnityEngine;
public class DayNightCycle : MonoBehaviour
{
public Light sun;
public float dayDuration = 120f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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));
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
if (currentTime >= dayDuration)
{
currentTime = 0f;
}
}
}