Advertisement
Pro_Unit

DateTimeTimer

Jan 17th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. using UnityEngine.UI;
  8. public class DateTimeTimer : MonoBehaviour
  9. {
  10.     [SerializeField] UnityEvent OnMoreThen;
  11.     [SerializeField] float seconds = 30f;
  12.     void Start ()
  13.     {
  14.         string dateTimeStringValue = PlayerPrefs.GetString ("TimeExit", DateTime.Now.ToString ());
  15.  
  16.         DateTime timeExit = new DateTime ();
  17.         DateTime.TryParse (dateTimeStringValue, out timeExit);
  18.  
  19.         TimeSpan deltaTime = timeExit.Subtract (DateTime.Now);
  20.  
  21.         if (deltaTime.Seconds >= seconds)
  22.         {
  23.             OnMoreThen.Invoke ();
  24.         }
  25.  
  26.     }
  27.     void OnApplicationQuit ()
  28.     {
  29.         PlayerPrefs.SetString ("TimeExit", DateTime.Now.ToString ());
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement