idk what thread to put this in.
how do i do somthing like this
DateTime d = System.DateTime.UtcNow.Day,System.DateTime.UtcNow.Month,System.DateTime.UtcNow.Year,9,00,00;
im trying to make a timer that runs outside of the app.
my scripts:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class TimerMaster : MonoBehaviour
{
DateTime currentDate;
DateTime oldDate;
public string saveLocation;
public static TimerMaster instance;
// Start is called before the first frame update
void Awake()
{
instance = this;
saveLocation = "lastSavedDate1";
}
public float CheckDate()
{
currentDate = System.DateTime.UtcNow;
string tempString = PlayerPrefs.GetString(saveLocation, "1");
long tempLong = Convert.ToInt64(tempString);
DateTime oldDate = DateTime.FromBinary(tempLong);
TimeSpan difference = currentDate.Subtract(oldDate);
return (float)difference.TotalSeconds;
}
public float MyCheckDate()
{
currentDate = System.DateTime.UtcNow;
DateTime d = System.DateTime.UtcNow.Day,System.DateTime.UtcNow.Month,System.DateTime.UtcNow.Year,9,00,00;
DateTime oldDate = Convert.ToDateTime(d);
TimeSpan difference = currentDate.Subtract(oldDate);
return (float)difference.TotalSeconds;
}
public void SaveDate()
{
PlayerPrefs.SetString(saveLocation, System.DateTime.Now.ToBinary().ToString());
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;
public class Timer : MonoBehaviour
{
public float timer;
public int t;
private bool Started = false;
public TMP_Text text;
// Start is called before the first frame update
void Start()
{
Started = PlayerPrefsX.GetBool("s");
if (Started)
{
timer = 86400;
timer -= TimerMaster.instance.CheckDate();
}
else
{
Started = true;
PlayerPrefsX.SetBool("s", Started);
timer = 86400;
timer -= TimerMaster.instance.MyCheckDate();
}
}
// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
if(timer <= 0)
{
float o = timer;
timer = 86400;
timer += o;
t += 1;
}
TimeSpan timeSpan = TimeSpan.FromSeconds(timer);
string timeText = string.Format("{0:smile:2}:{1:smile:2}:{2:smile:2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
text.text = timeText;
}
public void ResetTimer()
{
timer = 86400;
TimerMaster.instance.SaveDate();
PlayerPrefsX.SetBool("s", false);
}
}
i want the timer to end at 9 pm and restart i have everything but the 9.00 part