Advertisement
DaDogeDevelopment

Sun Rotate Script

Jun 3rd, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SunRotates : MonoBehaviour
  5. {
  6.  
  7.     [Range(0f, 24f)]
  8.     public float currentTime;   // 0 and 24 equal to 12am (midnight) , 12 euals to 12pm (noon)
  9.     public float dayLengthInSeconds; // How long (in second) do you want a day to last?
  10.  
  11.     void Start()
  12.     {
  13.  
  14.     }
  15.     void Update()
  16.     {
  17.         float speed = 24f / dayLengthInSeconds;
  18.  
  19.         currentTime += Time.deltaTime * speed;
  20.  
  21.         if (currentTime >= 24f)
  22.             currentTime = 0f;
  23.         transform.rotation = Quaternion.Euler((currentTime - 6) * 15f, 0f, 0f);
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement