/// ---------------------------------------------
/// Behavior Designer
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.BehaviorDesigner.Samples
{
using Opsive.BehaviorDesigner.Runtime.Tasks;
using Opsive.BehaviorDesigner.Runtime.Tasks.Actions;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
using UnityEngine.AI;
///
/// Uses the NavMeshAgent to seek to the specified target.
/// This task is basic intended for demo purposes. For a more complete task see the Movement Pack:
/// https://assetstore.unity.com/packages/slug/310243
///
[Shared.Utility.Category("Behavior Designer Samples")]
public class Flee : Action
{
[Tooltip("The seek destination.")]
[SerializeField] protected SharedVariable m_Destination;
private NavMeshAgent m_Agent;
///
/// Initializes the default values.
///
public override void OnAwake()
{
base.OnAwake();
m_Agent = GetComponent();
}
///
/// Sets the NavMesh destination.
///
public override void OnStart()
{
m_Agent.SetDestination(m_Destination.Value.transform.position);
}
///
/// Returns success when the agent has arrived.
///
/// Success when the agent has arrived.
public override TaskStatus OnUpdate()
{
if (!m_Agent.pathPending && m_Agent.remainingDistance <= m_Agent.stoppingDistance) {
return TaskStatus.Success;
}
if (m_Agent.destination != m_Destination.Value.transform.position) {
m_Agent.SetDestination(m_Destination.Value.transform.position);
}
return TaskStatus.Running;
}
}
}