// Jimmy Vegas Unity Tutorials // These scripts will create your QTE system using System.Collections; using System.Collections.Generic; using UnityEngine; public class FirstQTE : MonoBehaviour { public GameObject qteObject; public static int timesDone; void OnTriggerEnter() { qteObject.SetActive(true); GetComponent().enabled = false; } void Update () { if (timesDone == 3) { qteObject.SetActive(false); } } } //======================= using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class QTESystem : MonoBehaviour { public GameObject displayBox; public int QTEGen; public bool waitingForKey = true; public int correctKey; public GameObject passBox; void Update () { if (waitingForKey == true) { waitingForKey = false; QTEGen = Random.Range(1, 3); //start coroutine if (QTEGen == 1) { displayBox.GetComponent().text = "[R]"; } if (QTEGen == 2) { displayBox.GetComponent().text = "[T]"; } } if (QTEGen == 1) { if (Input.anyKeyDown) { if (Input.GetButtonDown("RKey")) { correctKey = 1; StartCoroutine(KeyPressing()); } else { correctKey = 2; StartCoroutine(KeyPressing()); } } } if (QTEGen == 2) { if (Input.anyKeyDown) { if (Input.GetButtonDown("TKey")) { correctKey = 1; StartCoroutine(KeyPressing()); } else { correctKey = 2; StartCoroutine(KeyPressing()); } } } } IEnumerator KeyPressing() { QTEGen = 4; if (correctKey == 1) { passBox.GetComponent().text = "Correct"; yield return new WaitForSeconds(1.5f); correctKey = 0; passBox.GetComponent().text = ""; displayBox.GetComponent().text = ""; yield return new WaitForSeconds(1.5f); FirstQTE.timesDone += 1; waitingForKey = true; } if (correctKey == 2) { passBox.GetComponent().text = "Incorrect"; yield return new WaitForSeconds(1.5f); correctKey = 0; passBox.GetComponent().text = ""; displayBox.GetComponent().text = ""; yield return new WaitForSeconds(1.5f); waitingForKey = true; } } }