From 657515cc0d9c322f7b8da08e7317e3ca557e32cf Mon Sep 17 00:00:00 2001 From: RochesterX Date: Sun, 9 Feb 2025 13:49:39 -0500 Subject: [PATCH] Add back block --- Assets/Scripts/Block.cs | 68 ++++++++++++++++++++++++++++++++++++ Assets/Scripts/Block.cs.meta | 2 ++ 2 files changed, 70 insertions(+) create mode 100644 Assets/Scripts/Block.cs create mode 100644 Assets/Scripts/Block.cs.meta diff --git a/Assets/Scripts/Block.cs b/Assets/Scripts/Block.cs new file mode 100644 index 0000000..b50222f --- /dev/null +++ b/Assets/Scripts/Block.cs @@ -0,0 +1,68 @@ +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; + + public bool blocking = false; + + private void Start() + { + actions = GetComponent().actions; + animationComponent = GetComponent(); + } + + private void Update() + { + var blockAction = actions.FindAction("Block"); + + if (blockAction.ReadValue() == 1f) + { + Debug.Log("Block action triggered!"); + + //if (!cancelable) return; + + //animationComponent.Play("Block"); + GetComponent().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; + } +} diff --git a/Assets/Scripts/Block.cs.meta b/Assets/Scripts/Block.cs.meta new file mode 100644 index 0000000..48a3bec --- /dev/null +++ b/Assets/Scripts/Block.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: c8c9288561905664eade3f6b2634fc6d \ No newline at end of file