using UnityEngine; namespace BehaviorDesigner.Runtime.Tactical { /// /// Example component which will attack by firing a bullet. /// public class Shootable : MonoBehaviour, IAttackAgent { // The bullet prefab to fire public GameObject bullet; // The furthest distance that the agent is able to attack from public float attackDistance; // The amount of time it takes for the agent to be able to attack again public float repeatAttackDelay; // The maximum angle that the agent can attack from public float attackAngle; // The last time the agent attacked private float lastAttackTime; /// /// Initialize the default values. /// private void Awake() { lastAttackTime = -repeatAttackDelay; } /// /// Returns the furthest distance that the agent is able to attack from. /// /// The distance that the agent can attack from. public float AttackDistance() { return attackDistance; } /// /// Can the agent attack? /// /// Returns true if the agent can attack. public bool CanAttack() { return lastAttackTime + repeatAttackDelay < Time.time; } /// /// Returns the maximum angle that the agent can attack from. /// /// The maximum angle that the agent can attack from. public float AttackAngle() { return attackAngle; } /// /// Does the actual attack. /// /// The position to attack. public void Attack(Vector3 targetPosition) { GameObject.Instantiate(bullet, transform.position, Quaternion.LookRotation(targetPosition - transform.position)); lastAttackTime = Time.time; } } }