using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEngine.EventSystems; public class Door : MonoBehaviour, IPointerClickHandler { GameObject cabinet; [HideInInspector] public bool isopen = false; [HideInInspector] public TextMeshProUGUI TextMeshProUGUI; Image Image; public void OnPointerClick(PointerEventData eventData) { if (isopen) { doorOpen(); } else { doorClose(); } } public void OnPointerUp(PointerEventData eventData) { } // Start is called before the first frame update void Start() { TextMeshProUGUI = transform.GetChild(0).GetComponent(); Image = GetComponent(); cabinet = transform.parent.parent.parent.gameObject; isopen = (cabinet.transform.GetChild(0).rotation != Quaternion.Euler(Vector3.zero)); if (isopen) { TextMeshProUGUI.text = "开门"; } else { TextMeshProUGUI.text = "关门"; } } // Update is called once per frame void Update() { } public void doorOpen() { GameManager.Inst.power_open(cabinet,"全开"); TextMeshProUGUI.text = "关门"; isopen = !isopen; } public void doorClose() { GameManager.Inst.power_close(cabinet, "全关"); TextMeshProUGUI.text = "开门"; isopen = !isopen; } }