70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
using System.Collections;
|
|
|
|
public class PirateIdle : PirateBehavior
|
|
{
|
|
[Header("Òàéìèíãè")]
|
|
public float waitDuration = 2f; // âðåìÿ îæèäàíèÿ ïîñëå ïðèõîäà
|
|
|
|
private bool isReturning = false;
|
|
|
|
|
|
public override void Activate()
|
|
{
|
|
enabled = true;
|
|
isReturning = true;
|
|
|
|
if (pirate.agent != null)
|
|
{
|
|
pirate.agent.SetDestination(pirate.HomePosition);
|
|
pirate.agent.isStopped = false;
|
|
|
|
// âêëþ÷àåì àíèìàöèþ õîäüáû
|
|
if (Animator != null)
|
|
{
|
|
Animator.Play("Idle");
|
|
Animator.SetBool("isWalking", true);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public override void Deactivate(bool interrupted = false)
|
|
{
|
|
StopAllCoroutines();
|
|
enabled = false;
|
|
isReturning = false;
|
|
|
|
|
|
if (Animator != null)
|
|
Animator.SetBool("isWalking", false);
|
|
|
|
pirate.ClearCurrentBehavior(this, interrupted);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!isReturning || pirate.agent == null) return;
|
|
|
|
// ïðîâåðêà, äîøëè ëè äî òî÷êè
|
|
if (!pirate.agent.pathPending && pirate.agent.remainingDistance <= pirate.agent.stoppingDistance)
|
|
{
|
|
pirate.agent.isStopped = true;
|
|
if (Animator != null)
|
|
Animator.SetBool("isWalking", false);
|
|
|
|
isReturning = false;
|
|
|
|
// ìîæíî ïîäîæäàòü íåáîëüøîå âðåìÿ
|
|
StartCoroutine(WaitCoroutine());
|
|
}
|
|
}
|
|
|
|
private IEnumerator WaitCoroutine()
|
|
{
|
|
yield return new WaitForSeconds(waitDuration);
|
|
Deactivate(true); // ïîñëå îæèäàíèÿ ïîâåäåíèå çàâåðøàåòñÿ
|
|
}
|
|
}
|