2025-02-09 13:49:39 -05:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(PlayerInput))]
|
|
|
|
|
public class Block : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public bool blocking = false;
|
2025-02-09 17:18:51 -05:00
|
|
|
private InputActionAsset actions;
|
2025-02-26 20:17:19 -05:00
|
|
|
private float blockPressTime = 0f;
|
|
|
|
|
private float parryThreshold = 0.2f;
|
|
|
|
|
private bool isParrying = false;
|
2025-02-09 13:49:39 -05:00
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
actions = GetComponent<PlayerInput>().actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
2025-02-09 17:18:51 -05:00
|
|
|
InputAction blockAction = actions.FindAction("Block");
|
2025-02-09 13:49:39 -05:00
|
|
|
if (blockAction.ReadValue<float>() == 1f)
|
|
|
|
|
{
|
2025-02-26 20:17:19 -05:00
|
|
|
if (!blocking)
|
|
|
|
|
{
|
|
|
|
|
blockPressTime = Time.time;
|
|
|
|
|
}
|
2025-02-09 17:18:51 -05:00
|
|
|
blocking = true;
|
2025-02-09 13:49:39 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-02-26 20:17:19 -05:00
|
|
|
if (blocking)
|
|
|
|
|
{
|
|
|
|
|
float pressDuration = Time.time - blockPressTime;
|
|
|
|
|
if (pressDuration <= parryThreshold)
|
|
|
|
|
{
|
|
|
|
|
Parry();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
isParrying = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-09 17:18:51 -05:00
|
|
|
blocking = false;
|
2025-02-09 13:49:39 -05:00
|
|
|
}
|
2025-02-09 17:18:51 -05:00
|
|
|
GetComponent<AnimationPlayer>().block = blocking;
|
2025-02-09 13:49:39 -05:00
|
|
|
}
|
2025-02-26 20:17:19 -05:00
|
|
|
|
|
|
|
|
private void Parry()
|
|
|
|
|
{
|
|
|
|
|
isParrying = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsParrying()
|
|
|
|
|
{
|
|
|
|
|
return isParrying;
|
|
|
|
|
}
|
2025-02-09 13:49:39 -05:00
|
|
|
}
|