Advertisement
Guest User

Example_

a guest
Jun 30th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class Manager : MonoBehaviour {
  6.  
  7.     public bool gameActive;
  8.  
  9.     //===Selector===
  10.     public GameObject selector;
  11.     public Camera cam;
  12.     public GameObject selected;
  13.     public float selectorTimer;
  14.     public bool runTimer;
  15.  
  16.     //===Time===
  17.     public int min;  //Converted Minutes
  18.     public int hour; //Converted Hours
  19.     public float absoluteTime; //True Time
  20.     public string currentTime;  //new Displayed Time
  21.     public string previousTime;  //previous Display Time. Used to stop frequent re-rendering of Time for performance
  22.     public float tempTime; //Trash_temporary time
  23.     public Text TimeDisplay;
  24.  
  25.     //===Pause===
  26.     public bool paused;
  27.     public GameObject PauseScreen;
  28.  
  29.     void Start () {
  30.         gameActive = true;
  31.         runTimer = false;
  32.         previousTime = " ";
  33.         paused = false;
  34.     }
  35.    
  36.  
  37.     void Update () {
  38.         if (gameActive) {
  39.             RunSelector ();
  40.             RunTime ();
  41.         }
  42.     }
  43.  
  44.     public void RunSelector(){
  45.         if (runTimer) {
  46.             selectorTimer += Time.deltaTime;
  47.         }
  48.         if (Input.GetMouseButtonDown (0)) {
  49.             RaycastHit hit;
  50.             Ray ray = cam.ScreenPointToRay (Input.mousePosition);
  51.  
  52.             if (Physics.Raycast (ray, out hit)) {
  53.                 if (selected != hit.transform.gameObject && hit.transform.name != "Selector") {
  54.                     runTimer = true;
  55.                     print (hit.transform.name);
  56.                     selected = hit.transform.gameObject;
  57.                     selector.transform.position = hit.transform.position;
  58.                     selectorTimer = 0;
  59.                 } else {
  60.                     print ("Already selected");
  61.                 }
  62.             }
  63.         }
  64.         if (selectorTimer >= 4 && runTimer) {
  65.             runTimer = false;
  66.             selector.transform.position = new Vector3 (0, -100, 0);
  67.             selected = selector;
  68.             selectorTimer = 0;
  69.         }
  70.     }
  71.  
  72.     //==========Running the overall game clock==========
  73.     public void RunTime(){
  74.         absoluteTime += Time.deltaTime;
  75.         //====Minutes====
  76.         if (absoluteTime >= .25) {
  77.             min += 1;
  78.             absoluteTime = 0;
  79.         }
  80.         //====Hours====
  81.         if (min >= 60) {
  82.             hour += 1;
  83.             min = 0;
  84.         }
  85.         if (hour >= 24) {
  86.             hour = 0;
  87.         }
  88.         //====Convert====
  89.         currentTime = hour.ToString("D2") + ":" + min.ToString("D2");
  90.         if (previousTime != currentTime) {
  91.             previousTime = currentTime;
  92.             TimeDisplay.text = currentTime;
  93.         }
  94.     }
  95.  
  96.     public void ControlPause(){
  97.         paused = !paused;
  98.         gameActive = !gameActive;
  99.         if (paused) {
  100.             PauseScreen.SetActive (true);
  101.         } else if (!paused) {
  102.             PauseScreen.SetActive (false);
  103.         } else {
  104.             Debug.Log ("ERROR: PAUSE");
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement