Added block animation, script, and keybind. Still need to add animation transitions/triggers.
This commit is contained in:
djkellerman
2025-01-31 11:27:03 -05:00
parent bbaebadbed
commit 36815eb876
8 changed files with 3061 additions and 6 deletions

View File

@@ -33,4 +33,9 @@ public class AnimationPlayer : MonoBehaviour
{
animator.SetTrigger("punch");
}
public void Block()
{
animator.SetTrigger("Block");
}
}

65
Assets/Scripts/Block.cs Normal file
View File

@@ -0,0 +1,65 @@
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(PlayerInput))]
[RequireComponent(typeof(Animation))]
public class Block : MonoBehaviour
{
public bool cancelable = true;
[SerializeField] private BoxCollider2D blockArea;
private InputActionAsset actions;
private Animation animationComponent;
private void Start()
{
actions = GetComponent<PlayerInput>().actions;
animationComponent = GetComponent<Animation>();
}
private void Update()
{
var blockAction = actions.FindAction("Block");
if (blockAction.triggered)
{
Debug.Log("Block action triggered!");
if (!cancelable) return;
animationComponent.Play("Block");
DisableCancellation();
ActivateBlockArea();
}
else
{
DeactivateBlockArea();
}
}
public void ActivateBlockArea()
{
blockArea.enabled = true;
}
public void DeactivateBlockArea()
{
blockArea.enabled = false;
}
public void DisableCancellation()
{
cancelable = false;
}
public void EnableCancellation()
{
cancelable = true;
}
public bool IsBlocking()
{
return blockArea.enabled;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c8c9288561905664eade3f6b2634fc6d