Advertisement
8ydilnik

Timer/audio/gameover

Sep 18th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class timer : MonoBehaviour
  7. {
  8.     public int time = 30;
  9.     public Text takeONme;
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {
  13.         StartCoroutine(timeon());
  14.     }
  15.  
  16.     // Update is called once per frame
  17.     void Update()
  18.     {
  19.  
  20.         takeONme.text = time.ToString();
  21.         //if time go over
  22.         if (time == 0)
  23.         {
  24.             iventsistem.instance.Ontime();
  25.         }
  26.     }
  27.  
  28.     //routin
  29.     public IEnumerator timeon()
  30.     {
  31.         //while time is longer zero
  32.         while(time > 0)
  33.         {
  34.             yield return new WaitForSeconds(1);
  35.             time -= 1;
  36.         }
  37.     }
  38. }
  39.  
  40. //
  41.  
  42. using System.Collections;
  43. using System.Collections.Generic;
  44. using UnityEngine;
  45.  
  46. public class audio : MonoBehaviour
  47. {
  48.     public GameObject proop;
  49.     public GameObject ulose;
  50.  
  51.     //signature to event
  52.     void Start()
  53.     {
  54.         proop.SetActive(false);
  55.     ulose.SetActive(false);
  56.  
  57.         iventsistem.instance.time += uloose;
  58.         iventsistem.instance.Win += uloose;
  59.         iventsistem.instance.Lose += uloose;
  60.  
  61.         iventsistem.instance.Sound += prooop;
  62.     }
  63.  
  64.     //sound ON
  65.     public void prooop()
  66.     {
  67.         proop.SetActive(true);
  68.         StartCoroutine(sound());
  69.     }
  70.  
  71.     //sound ON
  72.     public void uloose()
  73.     {
  74.         ulose.SetActive(true);      
  75.     }
  76.    
  77.     //routin
  78.     IEnumerator sound()
  79.     {
  80.         yield return new WaitForSeconds(0.2f);
  81.         proop.SetActive(false);
  82.     }
  83. }
  84.  
  85. ///
  86.  
  87. using System.Collections;
  88. using System.Collections.Generic;
  89. using UnityEngine;
  90. using UnityEngine.UI;
  91. public class GameOver : MonoBehaviour
  92. {
  93.     public Text losee;
  94.    
  95.     //signature to event
  96.     void Start()
  97.     {
  98.         iventsistem.instance.Win += win;
  99.         iventsistem.instance.Lose += lose;
  100.  
  101.     }
  102.  
  103.     //text output
  104.     public void lose()
  105.     {
  106.         losee.text = "you lose";
  107.  
  108.     }
  109.  
  110.     //text output
  111.     public void win()
  112.     {
  113.         losee.text = "you win";
  114.     }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement