Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class EnemyAI : MonoBehaviour {
- public ENEMY_STATE states;
- public void Awake() {
- states = ENEMY_STATE.IDLE;
- }
- public void Start() {
- StartCoroutine (EnemyFSM());
- }
- public enum ENEMY_STATE {
- IDLE = 0,
- CHASE = 1,
- ATTACK = 2
- }
- IEnumerator EnemyFSM() {
- while (true) {
- yield return StartCoroutine(states.ToString());
- }
- }
- IEnumerator IDLE() {
- Debug.Log ("IDLE STATE");
- while (states == ENEMY_STATE.IDLE) {
- yield return new WaitForSeconds(1.0f);
- Debug.Log ("Idling..");
- yield return new WaitForSeconds(1.0f);
- Debug.Log ("...and idling some more");
- }
- Debug.Log ("END IDLE STATE");
- }
- IEnumerator CHASE() {
- Debug.Log ("CHASE STATE");
- while (states == ENEMY_STATE.CHASE) {
- yield return new WaitForSeconds(1.0f);
- Debug.Log ("Chasing...");
- yield return new WaitForSeconds(1.0f);
- Debug.Log ("... I will get you");
- }
- Debug.Log ("END CHASE STATE");
- }
- IEnumerator ATTACK() {
- Debug.Log ("ATTACK STATE");
- while (states == ENEMY_STATE.ATTACK) {
- yield return new WaitForSeconds(1.0f);
- Debug.Log ("Attacking...");
- yield return new WaitForSeconds(1.0f);
- Debug.Log ("...Attacking some more");
- }
- Debug.Log ("END ATTACK STATE");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement