Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class Manager : MonoBehaviour {
- public bool gameActive;
- //===Selector===
- public GameObject selector;
- public Camera cam;
- public GameObject selected;
- public float selectorTimer;
- public bool runTimer;
- //===Time===
- public int min; //Converted Minutes
- public int hour; //Converted Hours
- public float absoluteTime; //True Time
- public string currentTime; //new Displayed Time
- public string previousTime; //previous Display Time. Used to stop frequent re-rendering of Time for performance
- public float tempTime; //Trash_temporary time
- public Text TimeDisplay;
- //===Pause===
- public bool paused;
- public GameObject PauseScreen;
- void Start () {
- gameActive = true;
- runTimer = false;
- previousTime = " ";
- paused = false;
- }
- void Update () {
- if (gameActive) {
- RunSelector ();
- RunTime ();
- }
- }
- public void RunSelector(){
- if (runTimer) {
- selectorTimer += Time.deltaTime;
- }
- if (Input.GetMouseButtonDown (0)) {
- RaycastHit hit;
- Ray ray = cam.ScreenPointToRay (Input.mousePosition);
- if (Physics.Raycast (ray, out hit)) {
- if (selected != hit.transform.gameObject && hit.transform.name != "Selector") {
- runTimer = true;
- print (hit.transform.name);
- selected = hit.transform.gameObject;
- selector.transform.position = hit.transform.position;
- selectorTimer = 0;
- } else {
- print ("Already selected");
- }
- }
- }
- if (selectorTimer >= 4 && runTimer) {
- runTimer = false;
- selector.transform.position = new Vector3 (0, -100, 0);
- selected = selector;
- selectorTimer = 0;
- }
- }
- //==========Running the overall game clock==========
- public void RunTime(){
- absoluteTime += Time.deltaTime;
- //====Minutes====
- if (absoluteTime >= .25) {
- min += 1;
- absoluteTime = 0;
- }
- //====Hours====
- if (min >= 60) {
- hour += 1;
- min = 0;
- }
- if (hour >= 24) {
- hour = 0;
- }
- //====Convert====
- currentTime = hour.ToString("D2") + ":" + min.ToString("D2");
- if (previousTime != currentTime) {
- previousTime = currentTime;
- TimeDisplay.text = currentTime;
- }
- }
- public void ControlPause(){
- paused = !paused;
- gameActive = !gameActive;
- if (paused) {
- PauseScreen.SetActive (true);
- } else if (!paused) {
- PauseScreen.SetActive (false);
- } else {
- Debug.Log ("ERROR: PAUSE");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement