Created
May 31, 2018 00:17
-
-
Save codehoose/ee7334b943970870a4d7f48213d8af6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
using UnityEngine.Events; | |
using UnityEngine.UI; | |
public class CountdownController : MonoBehaviour | |
{ | |
public int seconds = 10; | |
public Text countdown; | |
[SerializeField] | |
public TimerRunoutEvent timerRunoutEvent; | |
void Start() | |
{ | |
if (countdown == null) | |
{ | |
countdown = GetComponent<Text>(); | |
} | |
// TODO: REMOVE IN PRODUCTION! :) This is for debug only | |
StartCountdown(); | |
} | |
public void StopCountdown() | |
{ | |
StopAllCoroutines(); | |
} | |
public void StartCountdown() | |
{ | |
StartCoroutine(DoCountdown()); | |
} | |
IEnumerator DoCountdown() | |
{ | |
for (int i = seconds; i >= 0; i--) | |
{ | |
yield return new WaitForSeconds(1); | |
countdown.text = i.ToString(); | |
} | |
timerRunoutEvent.Invoke(); | |
} | |
} | |
[System.Serializable] | |
public class TimerRunoutEvent : UnityEvent | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.EventSystems; | |
using UnityEngine.UI; | |
public class QuitOrContinueController : MonoBehaviour | |
{ | |
public CountdownController countDownController; | |
public Button defaultButton; | |
void Start() | |
{ | |
EventSystem.current.SetSelectedGameObject(defaultButton.gameObject); | |
} | |
public void ContinueGame() | |
{ | |
countDownController.StopCountdown(); | |
// TODO: Continue | |
print("Continue the game!"); | |
} | |
public void QuitGame() | |
{ | |
countDownController.StopCountdown(); | |
// TODO: Quit | |
print("QUIT!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment