56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class DoorToggle : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
[SerializeField] private Animator animator;
|
|
|
|
[Header("Animator")]
|
|
[SerializeField] private string openParameterName = "IsOpen";
|
|
|
|
private bool isOpen;
|
|
|
|
private void Reset()
|
|
{
|
|
animator = GetComponent<Animator>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (animator == null)
|
|
{
|
|
Debug.LogError($"[{nameof(DoorToggle)}] Animator가 할당되지 않았습니다.", this);
|
|
enabled = false;
|
|
return;
|
|
}
|
|
|
|
isOpen = animator.GetBool(openParameterName);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Keyboard.current != null && Keyboard.current.oKey.wasPressedThisFrame)
|
|
{
|
|
ToggleDoor();
|
|
}
|
|
}
|
|
|
|
public void ToggleDoor()
|
|
{
|
|
isOpen = !isOpen;
|
|
animator.SetBool(openParameterName, isOpen);
|
|
}
|
|
|
|
public void OpenDoor()
|
|
{
|
|
isOpen = true;
|
|
animator.SetBool(openParameterName, isOpen);
|
|
}
|
|
|
|
public void CloseDoor()
|
|
{
|
|
isOpen = false;
|
|
animator.SetBool(openParameterName, isOpen);
|
|
}
|
|
} |