IEnumerator ChangeState(AIstates newState, float t) { yield return(new WaitForSeconds(t)); CurrentState = newState; isChanging = false; }
IEnumerator DelayNextWaypoint(float time, AIstates newstate) { yield return(new WaitForSeconds(time)); CurrentState = newstate; NextWaypoint(); }
IEnumerator DelayNextWaypoint(float time, AIstates newstate) { yield return(new WaitForSeconds(time)); NextWaypoint(); ChangeState(newstate); }
public void handleDeath() { if (States.EnemyHealth.fillAmount <= 0) { States.RotateToTarget = false; States.AgentAI.isStopped = true; _AiStates = AIstates.death; } }
void switchStates() { Timer -= Time.deltaTime; if (Timer < 0) { myState++; if (myState == AIstates.startOver) { myState = AIstates.wander; } Timer = StartTimer; } }
public void HandleCloseSight() { _Close++; if (_Close > CloseCOunt) { _Close = 0; if (Dis > Sight || _angle > FOV_Angle) { _AiStates = AIstates.far; return; } } RayCastToTarget(); }
public void HandleFarSight() { if (target == null) { return; } _Frame++; if (_Frame > frameCount) { _Frame = 0; if (Dis < Sight) { if (_angle < FOV_Angle) { _AiStates = AIstates.close; } } } }
public void In_Sight() { States.RotateToTarget = true; HandleCoolDown(); float disToDes = Vector3.Distance(States.TargetDestination, target.position); if (disToDes > 2 || Dis > Sight * 0.5) { GoToTarget(); } if (Dis < 2) { States.AgentAI.isStopped = true; } if (_AttackCount > 0) { _AttackCount--; return; } _AttackCount = AttackCount; BossAttacks a = WillAttack(); if (a != null) { States.anim.applyRootMotion = true; // States.AgentAI.enabled = false; _AiStates = AIstates.Attacking; States.anim.Play(a.targetAnim); States.CanMove = false; a.cool = a.CoolDown; States.AgentAI.isStopped = true; return; } }
public void RayCastToTarget() { RaycastHit hit; Vector3 Origin = transform.position; Origin.y += 0.5f; Vector3 dir = DirToTarget; dir.y += 0.5f; if (Physics.Raycast(Origin, dir, out hit, Sight, States.IgnoreLayers)) { StateManager st = hit.transform.GetComponent <StateManager>(); if (st != null) { States.anim.Play(Standingup); _AiStates = AIstates.InSight; States.RotateToTarget = true; // States.SetDestination(target.position); } } }
private void Update() { Delta = Time.deltaTime; Dis = DistanceFromTarget(); _angle = AngleTotarget(); if (target) { DirToTarget = target.position - transform.position; } if (Dis > Sight || _angle > FOV_Angle) { _AiStates = AIstates.far; BossHealth.SetActive(false); States.anim.Play(Idle); States.AgentAI.isStopped = true; } // checking player pos // updating. if (Dis < Sight) { PLAYERPOS = target.position; } handleDeath(); // checking dist is smaller if (Vector3.Distance(transform.position, PLAYERPOS) < 1f) { States.anim.SetFloat(EnemyMove, -1); } States.DirtoTarget = DirToTarget; switch (_AiStates) { case AIstates.far: HandleFarSight(); break; case AIstates.close: HandleCloseSight(); break; case AIstates.InSight: In_Sight(); BossHealth.SetActive(true); break; case AIstates.Attacking: if (States.CanMove) { _AiStates = AIstates.InSight; States.RotateToTarget = true; States.anim.SetFloat(EnemyMove, -1); } break; case AIstates.death: handleDeath(); break; default: break; } States.Tick(Delta); }
void ChangeState(AIstates newState) { CurrentState = newState; }