using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; using UnityEngine.EventSystems; public class RoomDoor : MonoBehaviour { public bool is_open; [SerializeField] private bool is_rotating; public Vector3 close_angle = new Vector3(-90, 0, 0); public Vector3 open_angle = new Vector3(-90, 0, 90); public RoomDoor another_door; void Start() { } void Update() { //Debug.Log(transform.name + " " + !is_rotating); } private void OnMouseDown() { if (!EventSystem.current.IsPointerOverGameObject() && is_open) { DoorClose(); } else { DoorOpen(); } } public void DoorOpen() { if (!is_rotating) { Debug.Log("开开始"); //DOTween.Kill(transform, false); is_rotating = true; //DOTween.To(() => transform.localEulerAngles, v => transform.localEulerAngles = v, open_angle, 0.5f).OnComplete(() => { is_rotating = false; is_open = true; }); transform.DOLocalRotate(open_angle, 0.5f).OnComplete(() => { Debug.Log("开结束"); is_rotating = false; is_open = true; }); if (another_door) another_door.DoorOpen(); } } public void DoorClose() { if (!is_rotating) { Debug.Log("关开始"); //DOTween.Kill(transform, false); is_rotating = true; //DOTween.To(() => transform.localEulerAngles, v => transform.localEulerAngles = v, close_angle, 0.5f).OnComplete(() => { is_rotating = false; is_open = false; }); transform.DOLocalRotate(close_angle, 0.5f).OnComplete(() => { Debug.Log("关结束"); is_rotating = false; is_open = false; }); if (another_door) another_door.DoorClose(); } } }