Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- public class Horloge : MonoBehaviour
- {
- public event Action OnDay;
- public event Action OnNight;
- private Transform tx;
- public float interval = 25;
- public float min = -90f;
- public float max = 180f;
- public float time = 0;
- public bool IsDay = false;
- public bool IsCurrentDay = false;
- void Start()
- {
- OnDay += () =>
- {
- Debug.Log("Day");
- };
- OnNight += () =>
- {
- Debug.Log("Night");
- };
- tx = GetComponent<Transform>();
- }
- void Update()
- {
- time += Time.deltaTime * 360f / interval;
- time %= 360f;
- IsDay = min < time && time < max;
- tx.localRotation = Quaternion.Euler(0, 0, -time);
- if (IsCurrentDay != IsDay)
- {
- IsCurrentDay = IsDay;
- OnDayNightChange();
- }
- }
- void OnDayNightChange()
- {
- if (IsDay)
- {
- OnDay?.Invoke();
- }
- else
- {
- OnNight?.Invoke();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment