2025-01-17 19:46:17 -05:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(PlayerInput))]
|
|
|
|
|
[RequireComponent(typeof(AnimationPlayer))]
|
|
|
|
|
public class Punch : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public bool cancelable = true;
|
|
|
|
|
|
|
|
|
|
[SerializeField] private BoxCollider2D hurtbox;
|
|
|
|
|
|
|
|
|
|
InputActionAsset actions;
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
actions = GetComponent<PlayerInput>().actions;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-28 17:39:07 -04:00
|
|
|
private void Update() // Executes punch when 'punch' is pressed
|
2025-01-17 19:46:17 -05:00
|
|
|
{
|
2025-02-08 18:54:21 -05:00
|
|
|
if (actions.FindAction("Punch").WasPressedThisFrame())
|
2025-01-17 19:46:17 -05:00
|
|
|
{
|
|
|
|
|
if (!cancelable) return;
|
2025-02-08 18:54:21 -05:00
|
|
|
ExecutePunch();
|
2025-01-17 19:46:17 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-28 17:39:07 -04:00
|
|
|
private void ExecutePunch() // Triggers punch animation
|
2025-02-08 18:54:21 -05:00
|
|
|
{
|
|
|
|
|
GetComponent<AnimationPlayer>().Punch();
|
|
|
|
|
DisableCancellation();
|
2025-03-28 17:39:07 -04:00
|
|
|
GetComponent<PlayerMovement>().maxSpeedOverride = 1f; // Slows player down when punching
|
2025-02-08 18:54:21 -05:00
|
|
|
}
|
|
|
|
|
|
2025-01-17 19:46:17 -05:00
|
|
|
public void EnableHurtbox()
|
|
|
|
|
{
|
2025-02-16 16:47:45 -05:00
|
|
|
if (hurtbox != null) hurtbox.enabled = true;
|
2025-01-17 19:46:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisableHurtbox()
|
|
|
|
|
{
|
2025-02-16 16:47:45 -05:00
|
|
|
if (hurtbox != null) hurtbox.enabled = false;
|
2025-01-17 19:46:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisableCancellation()
|
|
|
|
|
{
|
|
|
|
|
cancelable = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EnableCancellation()
|
|
|
|
|
{
|
|
|
|
|
cancelable = true;
|
|
|
|
|
}
|
2025-02-08 18:54:21 -05:00
|
|
|
|
2025-03-28 17:39:07 -04:00
|
|
|
public void ReturnToMaxSpeed() // Resets player speed after punch
|
2025-02-08 18:54:21 -05:00
|
|
|
{
|
|
|
|
|
GetComponent<PlayerMovement>().maxSpeedOverride = GetComponent<PlayerMovement>().maxSpeed;
|
|
|
|
|
}
|
2025-01-17 19:46:17 -05:00
|
|
|
}
|