// Use this for initialization void Start() { TimeToIncrement = 20; int noOfTickets = 0; isReplayGame = false; if (PlayerPrefs.HasKey("NoOfTickets")) { noOfTickets = PlayerPrefs.GetInt("NoOfTickets"); } else { noOfTickets = 5; PlayerPrefs.SetInt("NoOfTickets", noOfTickets); PlayerPrefs.Save(); } Debug.Log("No of Tickets=" + noOfTickets); if (noOfTickets < 5) { if (PlayerPrefs.HasKey("TicketDecrementedTime")) { DateTime TicketDecrementedTime = DateTime.Now; DateTime.TryParse(PlayerPrefs.GetString("TicketDecrementedTime"), out TicketDecrementedTime); if (TicketDecrementedTime != DateTime.Now) { TimeSpan TimeDiff = DateTime.Now - TicketDecrementedTime; Debug.Log("TimeDiff:" + TimeDiff.Minutes + ": " + TimeDiff.Seconds); while (TimeDiff.TotalSeconds > TimeToIncrement * 60 && noOfTickets < 5) { noOfTickets++; TimeDiff = TimeDiff.Subtract(TimeSpan.FromMinutes(TimeToIncrement)); } Debug.Log("TimeDiff:" + TimeDiff.Minutes + ": " + TimeDiff.Seconds); if (noOfTickets < 5) { TimeSpan TimerTime = TimeSpan.FromMinutes(TimeToIncrement) - TimeDiff; if (TimerCoroutineInstance != null) { StopCoroutine(TimerCoroutineInstance); } TimerCoroutineInstance = TimerCoroutine(TimerTime.Minutes, TimerTime.Seconds); StartCoroutine(TimerCoroutineInstance); } } } } NoOfTickets = noOfTickets; UpdateTicketText(NoOfTickets.ToString()); if (noOfTickets == 5) { UpdateTimerText("Full"); } }
public void DecrementTicket() { if (NoOfTickets == 5) { PlayerPrefs.SetString("TicketDecrementedTime", DateTime.Now.ToString()); PlayerPrefs.Save(); if (TimerCoroutineInstance != null) { StopCoroutine(TimerCoroutineInstance); } TimerCoroutineInstance = TimerCoroutine(TimeToIncrement, 0); StartCoroutine(TimerCoroutineInstance); } NoOfTickets--; UpdateTicketText(NoOfTickets.ToString()); }
public void IncrementTickets() { if (TimerCoroutineInstance != null) { StopCoroutine(TimerCoroutineInstance); } if ((NoOfTickets + 1) < 5) { TimerCoroutineInstance = TimerCoroutine(TimeToIncrement, 0); StartCoroutine(TimerCoroutineInstance); } else { UpdateTimerText("Full"); } NoOfTickets++; UpdateTicketText(NoOfTickets.ToString()); }