Advertisement
salahzar

Quiz.cs

Feb 10th, 2021
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Quiz : MonoBehaviour
  6. {
  7.     public GameObject bottoniera;
  8.     public GameObject esatta;
  9.     public GameObject sbagliata;
  10.  
  11.     public string chiave = "1324";
  12.  
  13.     public string codice = "";
  14.  
  15.     public float timeout = 0;
  16.    
  17.     // Start is called before the first frame update
  18.     void Start()
  19.     {
  20.         bottoniera.SetActive(true);
  21.         esatta.SetActive(false);
  22.         sbagliata.SetActive(false);
  23.         codice = "";
  24.         timeout = 0;
  25.  
  26.     }
  27.     public void clickBottone(string bottone)
  28.     {
  29.         codice += bottone;
  30.         if(codice == chiave)
  31.         {
  32.             click_esatta();
  33.         } else
  34.         {
  35.             timeout = 2;
  36.  
  37.         }
  38.  
  39.     }
  40.  
  41.    
  42.     public void click_esatta()
  43.     {
  44.         bottoniera.SetActive(false);
  45.         esatta.SetActive(true);
  46.         StartCoroutine(timer());
  47.        
  48.     }
  49.  
  50.     public void click_sbagliata()
  51.     {
  52.         bottoniera.SetActive(false);
  53.         sbagliata.SetActive(true);
  54.         StartCoroutine(timer());
  55.  
  56.     }
  57.  
  58.     // Update is called once per frame
  59.     void Update()
  60.     {
  61.         if (timeout > 0)
  62.         {
  63.             timeout -= Time.deltaTime;
  64.             if (timeout <= 0)
  65.             {
  66.                 timeout = 0;
  67.                 codice = "";
  68.             }
  69.         }
  70.     }
  71.  
  72.  
  73.     IEnumerator timer()
  74.     {
  75.         yield return new WaitForSeconds(2);
  76.         Start();
  77.  
  78.     }
  79.  
  80.    
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement