void OnEnterTextButton() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 10.0f)) { if (hit.transform != null) { if (hit.transform.gameObject == EnterCodeButton) { //play pressed button sound if (input == curPassword && Input.GetMouseButtonDown(0)) { CorrectCodeLight.GetComponent <MeshRenderer>().material = CorrectCodeLightOnMaterial; StartCoroutine(DisplayAuthorizedText()); } else if (input != curPassword && Input.GetMouseButtonDown(0)) { ErrorCodeLight.GetComponent <MeshRenderer>().material = ErrorCodeLightOnMaterial; StartCoroutine(DisplayErrorText()); } } } } }
IEnumerator DisplayErrorText() { yield return(new WaitForSeconds(0.5f)); CodeText.GetComponent <TextMesh>().text = "DENIED"; input = ""; yield return(new WaitForSeconds(1f)); CodeText.GetComponent <TextMesh>().text = input; ErrorCodeLight.GetComponent <MeshRenderer>().material = ErrorCodeLightOffMaterial; //play error sound }