Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- public class game : MonoBehaviour
- {
- GameObject Danger1;
- GameObject Danger2;
- GameObject Danger3;
- public Text incomingThreats;
- public Queue<Threat> threats = new Queue<Threat>();
- public class Threat{
- public int position;
- float finalTime;
- public Threat(){
- position = UnityEngine.Random.Range(1,4);
- finalTime = Time.time + 0.75f;
- }
- public bool CountDown(){
- if(Time.time >= finalTime){
- return true;
- }
- else{
- return false;
- }
- }
- }
- void Start()
- {
- Danger1=GameObject.Find("Danger1");
- Danger2=GameObject.Find("Danger2");
- Danger3=GameObject.Find("Danger3");
- incomingThreats.text = "";
- Danger1.SetActive (false);
- Danger2.SetActive (false);
- Danger3.SetActive (false);
- }
- bool waitActive = false;
- IEnumerator Wait(float seconds){
- waitActive = true;
- yield return new WaitForSeconds (seconds);
- waitActive = false;
- }
- IEnumerator ReactivateWithDelay(float seconds, GameObject obj){
- obj.SetActive (true);
- yield return new WaitForSeconds(seconds);
- obj.SetActive (false);
- }
- void ThreatGenerator(){
- if(!waitActive){
- StartCoroutine(Wait(1.0f));
- Threat incomingThreat = new Threat();
- threats.Enqueue(incomingThreat);
- DangerNotification(incomingThreat.position);
- }
- }
- void DangerNotification(int pos){
- switch (pos)
- {
- case 1:
- ReactivateWithDelay(1.0f, Danger1);
- break;
- case 2:
- ReactivateWithDelay(1.0f, Danger2);
- break;
- case 3:
- ReactivateWithDelay(1.0f, Danger3);
- break;
- }
- }
- int Fight(){
- if (Input.GetKeyDown("left")){
- return 1;
- }
- else if (Input.GetKeyDown("up")){
- return 2;
- }
- else if (Input.GetKeyDown("right")){
- return 3;
- }
- else{
- return 0;
- }
- }
- void Update()
- {
- ThreatGenerator();
- if (threats.Count != 0){
- incomingThreats.text = threats.Peek().position.ToString();
- }
- else{
- incomingThreats.text = "";
- }
- if (Fight()==threats.Peek().position){
- threats.Dequeue();
- }
- else if(Fight()!=0){
- incomingThreats.text = "You loose";
- }
- if (threats.Count !=0){
- if (threats.Peek().CountDown() == true){
- incomingThreats.text = "You loose";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement