public int waitSeconds = 3 * 60; // Interval for free gift: 3 minutes. void OnGUI() { if (textStyle == null) { SetUpStyles(); } GUILayout.BeginHorizontal(GUI.skin.label, GUILayout.Width(Screen.width)); GUILayout.Label("FreeGift:", textStyle); // Main routine: Control Free Gift. if (FreeGiftTimer.IsValid()) { if (FreeGiftTimer.CanSend()) { // Can get a free gift. if (GUILayout.Button("Get", buttonStyle)) { FreeGiftTimer.SetNextWait(waitSeconds); } } else { // Cannot get a free gift because the time has not yet come. GUILayout.Label("Next: " + FreeGiftTimer.GetRemainingTime() + " sec later", textStyle); } } else { // Cannot get a free gift because the clock is invalid. GUILayout.Label("Unavailable", textStyle); } GUILayout.EndHorizontal(); }
void Update() { if (isCollectingGift == true) { if (newAmount != previousStars + rewardAmount) { IncreaseCounter(1); } else if (isCollectingGift == true) { isCollectingGift = false; StartCoroutine(fade()); } } var newTimerState = GetTimerState(); if (newTimerState != timerState) { timerState = newTimerState; ChangeScreen(); } switch (timerState) { case TimerState.WAITING: if (isCollectingGift == false) { var sec = FreeGiftTimer.GetRemainingTime(); hours = FreeGiftTimer.GetRemainingTime() / 3600; mins = (FreeGiftTimer.GetRemainingTime() % 3600) / 60; secs = (FreeGiftTimer.GetRemainingTime() % 3600) % 60; //Debug.Log (hours); //Debug.Log (mins); //Debug.Log (secs); //FreeGiftTimer.SetNextWait(0); waitingText.text = string.Format("{0:00}:{1:00}:{2:00}", hours, mins, secs); // waitingText.text = string.Format ("{0} sec", sec); } break; } }