Beispiel #1
0
    // 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");
        }
    }
Beispiel #2
0
 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());
 }
Beispiel #3
0
 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());
 }