using UnityEngine; using System.Collections; public class DigitalPanelController : Predicate { private string _currentDigits = ""; public GameObject guiPrototype; private Canvas _guiInstance; public bool locked = true; public string password = "4815"; public PlayerSensor sensor; private GameAction _showPadAction; public string CurrentDigits { get { return _currentDigits; } set { _currentDigits = value; OnPasswordUpdated(); } } private void OnPasswordUpdated() { if (_currentDigits == password) { HideGui(); locked = false; } } public void ShowGui() { if (_guiInstance == null) { _guiInstance = ((GameObject)Instantiate(guiPrototype)).GetComponent(); _guiInstance.GetComponent().Panel = this; var c = FindObjectOfType(); c.ShowUI(_guiInstance.GetComponent()); Time.timeScale = 0; } } public void HideGui() { if (_guiInstance != null) { var c = FindObjectOfType(); c.ShowPreviousUi(true); Destroy(_guiInstance.gameObject); } Time.timeScale = 1; } // Use this for initialization void Start () { if (sensor != null) { sensor.PlayerEnter += sensor_PlayerEnter; sensor.PlayerExit += sensor_PlayerExit; } _showPadAction = new GameAction(gameObject, "use pad"); } bool GuiVisible() { return _guiInstance != null; } void OnAction(ActionArgs a) { if (!GuiVisible()) { ShowGui(); } } void sensor_PlayerExit(PlayerSensor senso, GameObject player) { ActionController.RemoveAction(_showPadAction); } void sensor_PlayerEnter(PlayerSensor senso, GameObject player) { if (locked) { ActionController.AddAction(_showPadAction); } } // Update is called once per frame void Update () { } protected override bool CheckInternal() { return locked; } protected override bool CheckInternal(object param) { return CheckInternal(); } }