2026-01-09 08:45:22 +03:00

72 lines
1.6 KiB
C#

using UnityEngine;
using UnityEngine.AI;
public class PirateBoxer : PirateBehavior
{
[Header("Ññûëêà íà àâòîìàò")]
public BoxingMachine targetMachine;
private bool isPunching = false;
public override void Activate()
{
enabled = true;
if (pirate.agent != null && targetMachine != null)
{
pirate.agent.SetDestination(targetMachine.hitPoint.position);
pirate.agent.isStopped = false;
if (Animator != null)
Animator.SetBool("isWalking", true);
}
}
public override void Deactivate(bool interrupted = false)
{
enabled = false;
if (pirate.agent != null)
pirate.agent.isStopped = true;
if (Animator != null)
{
Animator.SetBool("isWalking", false);
}
isPunching = false;
pirate.ClearCurrentBehavior(this, interrupted);
}
void Update()
{
if (pirate.agent == null || targetMachine == null) return;
if (!isPunching && !pirate.agent.pathPending && pirate.agent.remainingDistance <= pirate.agent.stoppingDistance)
{
pirate.agent.isStopped = true;
if (Animator != null)
{
Animator.SetBool("isWalking", false);
float index = Random.Range(0, 3); // 0 èëè 1
Animator.SetFloat("PunchIndex", index);
Animator.SetTrigger("Punch");
}
isPunching = true;
}
}
// Âûçûâàåòñÿ àíèìàöèåé ÷åðåç Animation Event
public void OnPunchImpact()
{
Deactivate(false);
targetMachine?.Hit();
}
}