Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ConsoleGame : BaseClass {
- float gameTime;
- int waitTime;
- // Use this for initialization
- void Start () {
- print ("welcome to the amazing console game: 'How many seconds?'.");
- GenerateRandomNumber ();
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown (KeyCode.Space)) {
- float playTime = Time.time - gameTime;
- float error = Mathf.Abs (waitTime - playTime);
- print ("You waited for : " + playTime + " seconds. That was " + error + " seconds off!");
- GenerateRandomNumber();
- }
- }
- void GenerateRandomNumber(){
- gameTime = Time.time;
- waitTime = Random.Range (5, 21);
- print ("wait for " + waitTime + " seconds");
- CountDownTimer (3);
- }
- void CountDownTimer (int countDownTime){
- for (int i=countDownTime; i > 0; i--) {
- MyInvoke (PrintCountdown, i, countDownTime-i);
- }
- MyInvoke (PrintGo, countDownTime);
- }
- void PrintCountdown (int countdownNumber){
- print (countdownNumber);
- }
- void PrintGo (){
- print ("go!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement