58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class PlayerAttack : MonoBehaviour
|
|
{
|
|
private InputManager _inputManager;
|
|
private LayerMask _enemyLayermask;
|
|
private Animate _animate;
|
|
private float _attackResetTime;
|
|
public void initialize(InputManager inputManager, LayerMask enemyLayermask, Animate animate, float attackResetTime)
|
|
{
|
|
_inputManager = inputManager;
|
|
_enemyLayermask = enemyLayermask;
|
|
|
|
_animate = animate;
|
|
animate.OnReset += HandleReset;
|
|
|
|
_attackResetTime = attackResetTime;
|
|
}
|
|
|
|
private bool _canAttack = true;
|
|
private int _attack = 1;
|
|
public void Attack()
|
|
{
|
|
if (_canAttack && _inputManager.attackPerformed)
|
|
{
|
|
if (_attack >= 3 || _animate.IsCurrentAnimation("Blend Tree"))
|
|
{
|
|
_attack = 1;
|
|
}
|
|
|
|
switch (_attack)
|
|
{
|
|
case 1:
|
|
_animate.TriggerAnimation("Left");
|
|
print("left");
|
|
break;
|
|
case 2:
|
|
_animate.TriggerAnimation("Right");
|
|
print("right");
|
|
break;
|
|
}
|
|
|
|
_canAttack = false;
|
|
_attack++;
|
|
}
|
|
}
|
|
|
|
public void HandleReset()
|
|
{
|
|
print("reset");
|
|
_canAttack = true;
|
|
}
|
|
}
|