50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Mirror;
|
|||
|
using StateMachine;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Player.States
|
|||
|
{
|
|||
|
public class MenuState : State<PlayerState>
|
|||
|
{
|
|||
|
private readonly Player _player;
|
|||
|
private static readonly int Anim = Animator.StringToHash("InMenu");
|
|||
|
private bool _canExitMenu;
|
|||
|
|
|||
|
public MenuState(Player player) : base(PlayerState.Menu)
|
|||
|
{
|
|||
|
_player = player;
|
|||
|
}
|
|||
|
|
|||
|
public override void Enter()
|
|||
|
{
|
|||
|
_player.OpenMenu();
|
|||
|
_player.animator.SetBool(Anim, true);
|
|||
|
Cursor.lockState = CursorLockMode.Confined;
|
|||
|
_canExitMenu = false;
|
|||
|
_player.StartCoroutine(EnableMenuExit());
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator EnableMenuExit()
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(0.5f);
|
|||
|
_canExitMenu = true;
|
|||
|
}
|
|||
|
|
|||
|
public override void Update()
|
|||
|
{
|
|||
|
if (_canExitMenu && Input.GetKeyDown(KeyCode.Escape) && _player.animator.GetBool(Anim) == true)
|
|||
|
{
|
|||
|
_player.StateMachine.SetCurrentState(PlayerState.Walk);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void Exit()
|
|||
|
{
|
|||
|
_player.CloseMenu();
|
|||
|
_player.animator.SetBool(Anim, false);
|
|||
|
Cursor.lockState = CursorLockMode.Locked;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|