mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-29 20:52:10 +01:00
first commit
This commit is contained in:
51
Assets/Scripts/TimeManager.cs
Normal file
51
Assets/Scripts/TimeManager.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
public class TimeManager : MonoBehaviour
|
||||
{
|
||||
public static Action OnMinuteChanged;
|
||||
public static Action OnHourChanged;
|
||||
public static Action OnDayChanged;
|
||||
|
||||
public static int Minute { get; private set; }
|
||||
public static int Hour { get; private set; }
|
||||
public static int Day { get; private set; }
|
||||
|
||||
private float minuteToRealTime = .5f;
|
||||
private float timer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Minute = 0;
|
||||
Hour = 10;
|
||||
Day = 1;
|
||||
timer = minuteToRealTime;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
|
||||
if (timer <= 0)
|
||||
{
|
||||
Minute++;
|
||||
OnMinuteChanged?.Invoke();
|
||||
if (Minute >= 60)
|
||||
{
|
||||
Hour++;
|
||||
Minute = 0;
|
||||
if (Hour >= 24)
|
||||
{
|
||||
Day++;
|
||||
Hour = 0;
|
||||
OnDayChanged();
|
||||
}
|
||||
|
||||
OnHourChanged();
|
||||
}
|
||||
|
||||
timer = minuteToRealTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user