﻿using LudumUtils.Extensions;
using UnityEngine;

namespace LudumUtils.Pausing {
    /// <summary>
    /// Controls a <see cref="PauseMotor"/> by checking whether a key is pressed.
    /// </summary>
    [RequireComponent(typeof(PauseMotor))]
    public class PauseController : LudumUtilsBehaviour {
        [SerializeField] private KeyCode _key = KeyCode.Escape;

        private PauseMotor _motor;

        private void Awake() {
            _motor = GetComponent<PauseMotor>();
        }

        private void Update() {
            if (_key.GetDown()) {
                _motor.Paused = !_motor.Paused;
            }
        }
    }
}
