Game Development Reference
In-Depth Information
042 //Total distance in Unity Units from current position that agent can wander when patrolling
043 public float PatrolDistance = 10.0f;
044
045 //Total distance enemy must be from player, in Unity Units, before chasing them
(entering chase state)
046 public float ChaseDistance = 10.0f;
047
048 //Total distance enemy must be from player before attacking them
049 public float AttackDistance = 0.1f;
050
051 //Enum of states for FSM
052 public enum ENEMY_STATE {PATROL = 0, CHASE = 1, ATTACK=2};
053
054 //Current state of enemy - default is patrol
055 public ENEMY_STATE ActiveState = ENEMY_STATE.PATROL;
056
057 //------------------------------------------------
058 //Called on object start
059 protected virtual void Start()
060 {
061 //Get NavAgent Component
062 Agent = GetComponent<NavMeshAgent>();
063
064 //Get Player Controller Component
065 GameObject PlayerObject = GameObject.Find("Player");
066 PC = PlayerObject.GetComponentInChildren<PlayerController>();
067
068 //Get Player Transform
069 PlayerTransform = PC.transform;
070
071 //Get Enemy Transform
072 ThisTransform = transform;
073
074 //Set default state
075 ChangeState(ActiveState);
076 }
077 //------------------------------------------------
078 //Change AI State
079 public void ChangeState(ENEMY_STATE State)
080 {
081 //Stops all AI Processing
082 StopAllCoroutines();
083
084 //Set new state
085 ActiveState = State;
086
Search WWH ::




Custom Search