//private bool isShooting; private void Update() { switch (_currentState) { case CowboyState.Wait: { var targetToAggro = gameObject.GetComponent <CheckAggroTest>().CheckForAggro(); if (targetToAggro != null) { _target = targetToAggro.GetComponent <NormalBoy>(); _currentState = CowboyState.Chase; } break; } case CowboyState.Chase: { if (_target == null) { _currentState = CowboyState.Wait; return; } agent.SetDestination(_target.transform.position); var targetToAggro = gameObject.GetComponent <CheckAggroTest>().CheckForAggro(); if (targetToAggro != null) { agent.SetDestination(_target.transform.position); _target = targetToAggro.GetComponent <NormalBoy>(); _currentState = CowboyState.Attack; } break; } case CowboyState.Attack: { RaycastHit hit; Physics.Raycast(transform.position, transform.forward, out hit, 20f); NormalBoy target = hit.transform.GetComponent <NormalBoy>(); if (target != null) { Destroy(target); } Debug.Log("attacking"); //isShooting = true; anim.SetBool("isShooting", true); if (_target == null) { _currentState = CowboyState.Wait; } break; } } }
public void ChangeState(CowboyState state) { this.stateCurrent = state; MakeState(); }