hi,
so i created a countdown timer script wich block the user from playing when he reachs a certain score and the user can play only when the timer reachs 00:00:00 .
The problem is that the timer starts from 11:59:59 and when the user exits the app and open it again after a period, the timer starts from 11:59:59 .
So, i need the timer to keep running even when the user exits the app.
also i need this task to be secured as much as possible so the player can’t hack it and bypass the timer.
my app is connected to a server if this can help.
this is my script :
private float timeRemaining = 43200;
public bool timerIsRunning = false;
public bool getTimeJustOnce = false;
public Text timerText;
private void Update()
{
int highscore = int.Parse(todayGains.text);
if(highscore == 1500)
{
startEarningButton.GetComponent<Collider2D>().enabled = false;
startEarningButton.GetComponent<Animator>().enabled = false;
if (timeRemaining > 0)
{
timeRemaining -= Time.deltaTime;
DisplayTime(timeRemaining);
PlayerPrefs.SetFloat("savedTime", timeRemaining);
}
else
{
while(timerIsRunning == true)
{
timerText.text = "";
timeRemaining = 0;
timerIsRunning = false;
startEarningButton.GetComponent<Collider2D>().enabled = true;
startEarningButton.GetComponent<Animator>().enabled = true;
PlayerPrefs.SetString("todayGains", "0");
todayGains.text = "0";
}
}
}
}
void DisplayTime(float timeToDisplay)
{
timeToDisplay -= 1;
float minutes = Mathf.FloorToInt(timeToDisplay / 60) % 60;
float seconds = Mathf.FloorToInt(timeToDisplay % 60);
float hours = Mathf.FloorToInt(timeToDisplay / 3600) % 24;
timerText.text = string.Format("ComeBack After : {0:00}:{1:00}:{2:00}", hours, minutes, seconds) ;
}