using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEngine.EventSystems; public class Door : MonoBehaviour, IPointerClickHandler { GameObject cabinet; bool isopen = false; TextMeshProUGUI TextMeshProUGUI; Image Image; public void OnPointerClick(PointerEventData eventData) { if (isopen) { GameManager.Inst.power_open(cabinet); TextMeshProUGUI.text = "关门"; isopen = !isopen; } else { GameManager.Inst.power_close(cabinet); TextMeshProUGUI.text = "开门"; isopen = !isopen; } } 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() { } }