parry and health bar pt1

This commit is contained in:
djkellerman
2025-02-26 20:17:19 -05:00
parent 710df1c8d4
commit 62c4a240b0
6 changed files with 114 additions and 15 deletions

View File

@@ -6,6 +6,9 @@ public class Block : MonoBehaviour
{
public bool blocking = false;
private InputActionAsset actions;
private float blockPressTime = 0f;
private float parryThreshold = 0.2f;
private bool isParrying = false;
private void Start()
{
@@ -15,16 +18,40 @@ public class Block : MonoBehaviour
private void Update()
{
InputAction blockAction = actions.FindAction("Block");
if (blockAction.ReadValue<float>() == 1f)
{
if (!blocking)
{
blockPressTime = Time.time;
}
blocking = true;
}
else
{
if (blocking)
{
float pressDuration = Time.time - blockPressTime;
if (pressDuration <= parryThreshold)
{
Parry();
}
else
{
isParrying = false;
}
}
blocking = false;
}
GetComponent<AnimationPlayer>().block = blocking;
}
private void Parry()
{
isParrying = true;
}
public bool IsParrying()
{
return isParrying;
}
}