40 lines
844 B
C#
40 lines
844 B
C#
|
|
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class ClockManager : MonoBehaviour
|
|
{
|
|
public Clock[] clocks;
|
|
|
|
void Start()
|
|
{
|
|
StartCoroutine(UpdateClocks());
|
|
}
|
|
|
|
IEnumerator UpdateClocks()
|
|
{
|
|
while (true)
|
|
{
|
|
// Read the computer's local time.
|
|
DateTime now = DateTime.Now;
|
|
|
|
// Synchronize every clock.
|
|
foreach (Clock clock in clocks)
|
|
{
|
|
if (clock != null)
|
|
{
|
|
clock.SetTime(now);
|
|
}
|
|
}
|
|
|
|
// Wait until approximately the next minute.
|
|
now = DateTime.Now;
|
|
float waitTime =
|
|
60f - now.Second - now.Millisecond / 1000f;
|
|
|
|
yield return new WaitForSecondsRealtime(waitTime);
|
|
}
|
|
}
|
|
}
|