/// <summary> /// Registers a state that can trigger itself at any time. The state must inherit from BotAIState and implement Trigger() static method. /// See DefendState for an example. /// </summary> /// <param name="t"></param> protected void RegisterState(AITrigger t) { if (!TriggerStates.Contains(t)) { TriggerStates.Add(t); } }
protected override void Awake() { base.Awake(); if (_agent) { _agent = GetComponent <NavMeshAgent>(); } if (_playerTrigger == null) { _playerTrigger = FindObjectOfType <AITrigger>(); } _originalAcceleration = _agent.acceleration; for (int i = 0; i < transform.parent.childCount; i++) { var point = transform.parent.GetChild(i).GetComponent <EscapePoint>(); if (point == null) { continue; } _escapePoints.Add(point); } }
private void Start() { if (_mainCamera == null) { _mainCamera = FindObjectOfType <Camera>(); } _aITrigger = FindObjectOfType <AITrigger>(); _sprite = GetComponent <SpriteRenderer>(); }
// Update is called once per frame void Update() { AITrigger trigger_scr = triggerO.GetComponent <AITrigger>(); string direction = trigger_scr.direction; drive(direction); transform.Translate(0, 0, speed * Time.deltaTime); if (trigger_scr.speedDir != 0) { float rotY = transform.rotation.eulerAngles.y - transform.rotation.eulerAngles.y % 10; rot.enabled = true; if (c == 1) { rot.spd = rot.spd * trigger_scr.speedDir; c = 0; } if ((System.Math.Abs(rotY) == 90 || System.Math.Abs(rotY) == 270) && !flag) { c = 1; flag = true; rot.enabled = false; trigger_scr.speedDir = 0; Debug.Log(rot.enabled); } if ((System.Math.Abs(rotY) == 0 || System.Math.Abs(rotY) == 180) && flag) { c = 1; flag = false; rot.enabled = false; trigger_scr.speedDir = 0; Debug.Log(rot.enabled); } } }
/// <summary> /// Registers a state that can trigger itself at any time. The state must inherit from BotAIState and implement Trigger() static method. /// See DefendState for an example. /// </summary> /// <param name="t"></param> protected void RegisterState(AITrigger t) { if (!TriggerStates.Contains(t)) TriggerStates.Add(t); }
public StateBasedAIComponent <T> WithTrigger(AITrigger trigger) { triggers.Add(trigger); return(this); }