Add back block
This commit is contained in:
68
Assets/Scripts/Block.cs
Normal file
68
Assets/Scripts/Block.cs
Normal file
@@ -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<PlayerInput>().actions;
|
||||||
|
animationComponent = GetComponent<Animation>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
var blockAction = actions.FindAction("Block");
|
||||||
|
|
||||||
|
if (blockAction.ReadValue<float>() == 1f)
|
||||||
|
{
|
||||||
|
Debug.Log("Block action triggered!");
|
||||||
|
|
||||||
|
//if (!cancelable) return;
|
||||||
|
|
||||||
|
//animationComponent.Play("Block");
|
||||||
|
GetComponent<AnimationPlayer>().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;
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/Block.cs.meta
Normal file
2
Assets/Scripts/Block.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c8c9288561905664eade3f6b2634fc6d
|
||||||
Reference in New Issue
Block a user