Advertisement
SebastianLague

Console Game (thomas)

Apr 3rd, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ConsoleGame : BaseClass {
  5.  
  6.     float gameTime;
  7.     int waitTime;
  8.  
  9.     // Use this for initialization
  10.     void Start () {
  11.         print ("welcome to the amazing console game: 'How many seconds?'.");
  12.         GenerateRandomNumber ();
  13.  
  14.  
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update () {
  19.         if (Input.GetKeyDown (KeyCode.Space)) {
  20.             float playTime = Time.time - gameTime;
  21.             float error = Mathf.Abs (waitTime - playTime);
  22.             print ("You waited for : " + playTime + " seconds. That was " + error + " seconds off!");
  23.             GenerateRandomNumber();
  24.         }
  25.  
  26.     }
  27.  
  28.     void GenerateRandomNumber(){
  29.         gameTime = Time.time;
  30.         waitTime = Random.Range (5, 21);
  31.         print ("wait for " + waitTime + " seconds");
  32.         CountDownTimer (3);
  33.     }
  34.  
  35.     void CountDownTimer (int countDownTime){
  36.         for (int i=countDownTime; i > 0; i--) {
  37.             MyInvoke (PrintCountdown, i, countDownTime-i);
  38.         }
  39.         MyInvoke (PrintGo, countDownTime);
  40.     }
  41.  
  42.     void PrintCountdown (int countdownNumber){
  43.         print (countdownNumber);
  44.     }
  45.  
  46.     void PrintGo (){
  47.         print ("go!");
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement