Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- public class DateTimeTimer : MonoBehaviour {
- public HardWorking HardWorking;
- public float seconds;
- public bool Cur;
- public bool Prib;
- public int CutInt;
- public int PribInt;
- void Start () {
- if (PlayerPrefs.GetInt ("CurInt1") == 1) {
- CutInt = 1;
- Cur = true;
- }
- if (PlayerPrefs.GetInt ("BribInt1") == 1) {
- Prib = true;
- PribInt = 1;
- }
- string dateTimeStringValue = PlayerPrefs.GetString ("TimeExit", DateTime.Now.ToString ());
- seconds = PlayerPrefs.GetFloat ("Now");
- DateTime timeExit = new DateTime ();
- DateTime.TryParse (dateTimeStringValue, out timeExit);
- TimeSpan deltaTime = DateTime.Now.Subtract (timeExit);
- if (deltaTime.Seconds >= seconds) {
- if (Cur) {
- HardWorking.TimerCur[0] = 0;
- Debug.Log ("Set timerCur is 0");
- }
- if (Prib) {
- HardWorking.TimerPrib[0] = 0;
- Debug.Log ("Set timerPrib is 0");
- }
- } else {
- if (deltaTime.Seconds < seconds) {
- if (Cur) {
- float TimeC = PlayerPrefs.GetFloat ("SaveTimerCur1");
- TimeC -= deltaTime.Seconds;
- HardWorking.TimerCur[0] = TimeC;
- HardWorking.ButtonZak[0].interactable = false;
- }
- if (Prib) {
- float TimeP = PlayerPrefs.GetFloat ("SaveTimerPrib1");
- TimeP -= deltaTime.Seconds;
- HardWorking.TimerPrib[0] = TimeP;
- HardWorking.ButtonZak[0].interactable = false;
- }
- }
- }
- }
- void OnApplicationQuit () {
- PlayerPrefs.SetString ("TimeExit", DateTime.Now.ToString ());
- PlayerPrefs.SetFloat ("SaveTimerCur1", HardWorking.TimerCur[0]);
- PlayerPrefs.SetFloat ("SaveTimerPrib1", HardWorking.TimerPrib[0]);
- PlayerPrefs.SetFloat ("Now", seconds);
- PlayerPrefs.SetInt ("CurInt1", CutInt);
- PlayerPrefs.SetInt ("BribInt1", PribInt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement