есть таймер на 10 минут
есть время отсутствия в приложении,
как вычесть правильнее что то не получается
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class TimerTest : MonoBehaviour
{
static public bool gameoverMet = false;
public static float mliSecond;
public static float second;
public static float minute =10;
public static float minute2;
public static float second2;
public static float Days;
public static float Hours;
#region Singleton
public static TimerTest Instance { get; private set; }
private void InitSingleton()
{
Instance = this;
}
#endregion
public Text text;
// Start is called before the first frame update
public static void Start()
{
if (PlayerPrefs.HasKey("333"))
{
MissionDemolition.GameOver();
PlayerPrefs.GetFloat("333", minute);
PlayerPrefs.GetFloat("444", second);
if (Days == 0 && Hours == 0)
{
if (minute2 < 10)
{
minute -= minute2;
second -= second2;
}
}
}
}
// Update is called once per frame
public static void FixedUpdate()
{
}
void Update()
{
PlayerPrefs.SetFloat("333", minute);
PlayerPrefs.SetFloat("444", second);
if (MissionDemolition.GOW == true)
{
mliSecond += Time.deltaTime;
if (mliSecond >= 1)
{
second--;
mliSecond = 0;
}
if (second == 0)
{
minute--;
second = 59;
}
if (minute == 0 && second <= 1)
{
print("GGGGGGGGG");
MissionDemolition.Gamenext();
TimerTest.gameoverMet = false;
}
text.text = $"{minute} : {second}";
if (TimerTest.gameoverMet == true)
{
minute = 10;
second = 0;
}
}
}
void Awake()
{
InitSingleton();
CheckOffline();
}
void CheckOffline()
{
TimeSpan ts;
if (PlayerPrefs.HasKey("LastSession"))
{
ts = DateTime.Now - DateTime.Parse(PlayerPrefs.GetString("LastSession"));
print(string.Format("Вы отсутствовали:{0} дней, {1} часов,{2} минут,{3} секунд", ts.Days, ts.Hours, ts.Minutes, ts.Seconds));
}
PlayerPrefs.SetString("LastSession", DateTime.Now.ToString());
minute2 = ts.Minutes;
second2 = ts.Seconds;
Days = ts.Days;
Hours = ts.Hours;
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class TimerTest : MonoBehaviour
{
static public bool gameoverMet = false;
public static float mliSecond;
public static float second;
public static float minute =10;
public static float minute2;
public static float second2;
public static float Days;
public static float Hours;
#region Singleton
public static TimerTest Instance { get; private set; }
private void InitSingleton()
{
Instance = this;
}
#endregion
public Text text;
// Start is called before the first frame update
public static void Start()
{
if (PlayerPrefs.HasKey("333"))
{
MissionDemolition.GameOver();
PlayerPrefs.GetFloat("333", minute);
PlayerPrefs.GetFloat("444", second);
if (Days == 0 && Hours == 0)
{
if (minute2 < 10)
{
minute -= minute2;
second -= second2;
}
}
}
}
// Update is called once per frame
public static void FixedUpdate()
{
}
void Update()
{
PlayerPrefs.SetFloat("333", minute);
PlayerPrefs.SetFloat("444", second);
if (MissionDemolition.GOW == true)
{
mliSecond += Time.deltaTime;
if (mliSecond >= 1)
{
second--;
mliSecond = 0;
}
if (second == 0)
{
minute--;
second = 59;
}
if (minute == 0 && second <= 1)
{
print("GGGGGGGGG");
MissionDemolition.Gamenext();
TimerTest.gameoverMet = false;
}
text.text = $"{minute} : {second}";
if (TimerTest.gameoverMet == true)
{
minute = 10;
second = 0;
}
}
}
void Awake()
{
InitSingleton();
CheckOffline();
}
void CheckOffline()
{
TimeSpan ts;
if (PlayerPrefs.HasKey("LastSession"))
{
ts = DateTime.Now - DateTime.Parse(PlayerPrefs.GetString("LastSession"));
print(string.Format("Вы отсутствовали:{0} дней, {1} часов,{2} минут,{3} секунд", ts.Days, ts.Hours, ts.Minutes, ts.Seconds));
}
PlayerPrefs.SetString("LastSession", DateTime.Now.ToString());
minute2 = ts.Minutes;
second2 = ts.Seconds;
Days = ts.Days;
Hours = ts.Hours;
}
}