/// ---------------------------------------------
/// 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.BehaviorDesigner.Samples.SceneManagers;
using Opsive.GraphDesigner.Runtime.Variables;
using UnityEngine;
///
/// Attacks the player.
///
[Shared.Utility.Category("Behavior Designer Samples")]
public class Attack: Action
{
[Tooltip("The agent that should attack.")]
[RequireShared]
[SerializeField] protected SharedVariable m_AttackAgent;
private GameObject m_Player;
private Health m_PlayerHealth;
///
/// Initializes the values.
///
public override void OnAwake()
{
var turnManager = GetComponent();
m_Player = turnManager.Player;
m_PlayerHealth = m_Player.GetComponent();
}
///
/// Select an agent that should attack.
///
/// Success if an agent was found.
public override TaskStatus OnUpdate()
{
// The player has to be alive.
if (m_PlayerHealth.Value <= 0) {
return TaskStatus.Failure;
}
var controller = m_AttackAgent.Value.GetComponent();
controller.Attack(m_Player);
return TaskStatus.Success;
}
}
}