Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class EnemyAI : MonoBehaviour {
  5.  
  6. public ENEMY_STATE states;
  7.  
  8. public void Awake() {
  9.  
  10. states = ENEMY_STATE.IDLE;
  11.  
  12.  
  13. }
  14.  
  15. public void Start() {
  16.  
  17. StartCoroutine (EnemyFSM());
  18.  
  19.  
  20. }
  21.  
  22. public enum ENEMY_STATE {
  23.  
  24.  
  25. IDLE = 0,
  26. CHASE = 1,
  27. ATTACK = 2
  28.  
  29. }
  30.  
  31.  
  32. IEnumerator EnemyFSM() {
  33.  
  34. while (true) {
  35.  
  36. yield return StartCoroutine(states.ToString());
  37.  
  38.  
  39. }
  40.  
  41. }
  42.  
  43. IEnumerator IDLE() {
  44.  
  45. Debug.Log ("IDLE STATE");
  46.  
  47. while (states == ENEMY_STATE.IDLE) {
  48.  
  49. yield return new WaitForSeconds(1.0f);
  50.  
  51. Debug.Log ("Idling..");
  52.  
  53. yield return new WaitForSeconds(1.0f);
  54.  
  55. Debug.Log ("...and idling some more");
  56.  
  57. }
  58.  
  59. Debug.Log ("END IDLE STATE");
  60.  
  61. }
  62.  
  63. IEnumerator CHASE() {
  64.  
  65. Debug.Log ("CHASE STATE");
  66.  
  67. while (states == ENEMY_STATE.CHASE) {
  68.  
  69. yield return new WaitForSeconds(1.0f);
  70.  
  71. Debug.Log ("Chasing...");
  72.  
  73. yield return new WaitForSeconds(1.0f);
  74.  
  75. Debug.Log ("... I will get you");
  76.  
  77. }
  78.  
  79. Debug.Log ("END CHASE STATE");
  80.  
  81.  
  82. }
  83.  
  84. IEnumerator ATTACK() {
  85.  
  86. Debug.Log ("ATTACK STATE");
  87.  
  88. while (states == ENEMY_STATE.ATTACK) {
  89.  
  90. yield return new WaitForSeconds(1.0f);
  91.  
  92. Debug.Log ("Attacking...");
  93.  
  94. yield return new WaitForSeconds(1.0f);
  95.  
  96. Debug.Log ("...Attacking some more");
  97.  
  98. }
  99.  
  100. Debug.Log ("END ATTACK STATE");
  101.  
  102.  
  103. }
  104.  
  105.  
  106.  
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement