using UnityEngine; using System.Collections; public class Keypad : MonoBehaviour { public string curPassword = "12345"; public string input; public bool onTrigger; public bool doorOpen; public bool keypadScreen; public Transform doorHinge; void OnTriggerEnter(Collider other) { onTrigger = true; } void OnTriggerExit(Collider other) { onTrigger = false; keypadScreen = false; input = ""; } void Update() { if(input == curPassword) { doorOpen = true; } if(doorOpen) { var newRot = Quaternion.RotateTowards(doorHinge.rotation, Quaternion.Euler(0.0f, -90.0f, 0.0f), Time.deltaTime * 250); doorHinge.rotation = newRot; } } void OnGUI() { if(!doorOpen) { if(onTrigger) { GUI.Box(new Rect(0, 0, 200, 25), "Press 'E' to open keypad"); if(Input.GetKeyDown(KeyCode.E)) { keypadScreen = true; onTrigger = false; } } if(keypadScreen) { GUI.Box(new Rect(0, 0, 320, 35), ""); GUI.Box(new Rect(5, 5, 310, 25), input); GUI.Label(new Rect(5, 30, 100, 25), "Press Esc to exit"); if(Input.GetKeyDown(Keycode.Escape)) { input = false; keypadScreen = false; } if(Input.GeyKeyDown(KeyCode.Alpha0) || Input.GeyKeyDown(Keycode.Keypad0)) { input = input + "0"; } if(Input.GeyKeyDown(KeyCode.Alpha1) || Input.GeyKeyDown(Keycode.Keypad1)) { input = input + "1"; } if(Input.GeyKeyDown(KeyCode.Alpha2) || Input.GeyKeyDown(Keycode.Keypad2)) { input = input + "2"; } if(Input.GeyKeyDown(KeyCode.Alpha3) || Input.GeyKeyDown(Keycode.Keypad3)) { input = input + "3"; } if(Input.GeyKeyDown(KeyCode.Alpha4) || Input.GeyKeyDown(Keycode.Keypad4)) { input = input + "4"; } if(Input.GeyKeyDown(KeyCode.Alpha5) || Input.GeyKeyDown(Keycode.Keypad5)) { input = input + "5"; } if(Input.GeyKeyDown(KeyCode.Alpha6) || Input.GeyKeyDown(Keycode.Keypad6)) { input = input + "6"; } if(Input.GeyKeyDown(KeyCode.Alpha7) || Input.GeyKeyDown(Keycode.Keypad7)) { input = input + "7"; } if(Input.GeyKeyDown(KeyCode.Alpha8) || Input.GeyKeyDown(Keycode.Keypad8)) { input = input + "8"; } if(Input.GeyKeyDown(KeyCode.Alpha9) || Input.GeyKeyDown(Keycode.Keypad9)) { input = input + "9"; } } } } }