62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
|
|
public class RoomDoor : MonoBehaviour
|
|
{
|
|
public bool is_open;
|
|
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()
|
|
{
|
|
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
if (is_open)
|
|
{
|
|
DoorClose();
|
|
}
|
|
else
|
|
{
|
|
DoorOpen();
|
|
}
|
|
}
|
|
|
|
public void DoorOpen()
|
|
{
|
|
if (!is_rotating)
|
|
{
|
|
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(() => { is_rotating = false; is_open = true; });
|
|
if (another_door)
|
|
another_door.DoorOpen();
|
|
}
|
|
}
|
|
|
|
public void DoorClose()
|
|
{
|
|
if (!is_rotating)
|
|
{
|
|
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(() => { is_rotating = false; is_open = false; });
|
|
if (another_door)
|
|
another_door.DoorClose();
|
|
}
|
|
}
|
|
}
|