Newer
Older
Hierarchical-Task-Network-Unity-3D / Assets / Scripts / Environment / EntranceDoor.cs
using UnityEngine;

public class EntranceDoor : MonoBehaviour
{
    private Animator animator;
    [SerializeField] private float currentTimer = 0f;
    [SerializeField] private float maxTimer = 1.5f;
    [SerializeField] private bool isOpen = false;


    private void Awake()
    {
        animator = GetComponent<Animator>();
    }

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (currentTimer != 0f)
        {
            currentTimer -= Time.deltaTime;

            if (currentTimer <= 0)
            {
                currentTimer = 0f;
                animator.SetBool("IsOpen", false);
            }
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        isOpen = true;
        animator.SetBool("IsOpen", true);
    }

    private void OnTriggerExit(Collider other)
    {
        currentTimer = maxTimer;
    }
}