Guest User

Untitled

a guest
Nov 6th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. enum ENEMY_STATE
  2. {
  3. STATE_MOVE = 0,
  4. STATE_FOLLOW
  5.  
  6. }
  7.  
  8. var exitdisabled = false;
  9. var disableobject =false;
  10. // variables
  11. //defines current state
  12. var currentState :ENEMY_STATE = ENEMY_STATE.STATE_MOVE;
  13. //players position
  14. var player : Transform;
  15. //enemys position
  16. var enemy : Transform;
  17. //enemys gameobject
  18. var enemyO : GameObject;
  19. //enemys rotation speed
  20. var enemyrotationspeed :float = 10;
  21. //enemys speed
  22. var enemyspeed : float = 6;
  23. //enemys jump hight
  24. var enemyjumpspeed : float = 36;
  25. var disabled : boolean = false;
  26. //enemys target when its not player
  27.  
  28. var target: Transform;
  29. var target1: Transform;
  30.  
  31. var enemycheckpoint1:GameObject;
  32. var enemycheckpoint2:Transform;
  33. var enemycheckpoint3:GameObject;
  34.  
  35.  
  36. // min distance
  37. var maxdistance : float = 0.6;
  38. var mindistance : float = 0.3;
  39. var isgrounded : boolean = false;
  40.  
  41. var fallspeed : float = 7.0;
  42.  
  43.  
  44.  
  45. function Start()
  46. {
  47.  
  48. target = enemycheckpoint1.transform;
  49. target1 = enemycheckpoint1.transform;
  50. enemyspeed = 0.25;
  51. }
  52. function Update()
  53. {
  54. if(disableobject == false)
  55. {
  56. if(isgrounded == true)
  57. {
  58. if(currentState == ENEMY_STATE.STATE_FOLLOW)
  59. {
  60. target1 = player.transform;
  61. if(Vector3.Distance(enemy.transform.position, player.transform.position) > mindistance)
  62. {
  63. enemy.transform.LookAt(Vector3(player.position.x,transform.position.y,player.position.z));
  64. transform.eulerAngles = Vector3(0,transform.localEulerAngles.y,0);
  65. if(disabled == false)
  66. {
  67. enemy.transform.position = Vector3.MoveTowards(enemy.transform.position,Vector3(player.transform.position.x,enemy.transform.position.y,player.transform.position.z),Time.deltaTime * enemyspeed); }
  68.  
  69. }
  70. else
  71. {
  72.  
  73. }
  74.  
  75. }
  76. if(currentState == ENEMY_STATE.STATE_MOVE)
  77. {
  78.  
  79. enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, Quaternion.LookRotation(target1.transform.position -enemy.transform.position), enemyrotationspeed * Time.deltaTime);
  80. if(disabled ==false)
  81. {
  82. enemy.transform.position = Vector3.MoveTowards(enemy.transform.position,target.transform.position,Time.deltaTime * enemyspeed);
  83. }
  84. }
  85. else
  86. {
  87. }
  88.  
  89. }
  90. if(isgrounded ==false)
  91. {
  92. enemy.transform.position.y -= fallspeed * Time.deltaTime;
  93. }
  94. }
  95. }
  96. function OnCollisionEnter(theCollision:Collision)
  97. {
  98. if(theCollision.gameObject.tag == "ground")
  99. {
  100. isgrounded = true;
  101. Debug.Log("is grounded");
  102. }
  103.  
  104. if(theCollision.gameObject.tag == "enemycheckpoint2")
  105. {
  106. enemy.transform.position = enemycheckpoint3.transform.position;
  107. enemy.transform.rotation = enemycheckpoint3.transform.rotation;
  108. isgrounded = false;
  109. exitdisabled = false;
  110. enemyspeed = 0.25;
  111. disableobject = true;
  112.  
  113. }
  114.  
  115.  
  116. }
  117. function OnTriggerEnter(other:Collider)
  118. {
  119. if(other.gameObject.tag == "enemycheckpoint1")
  120. {
  121. isgrounded = true;
  122. exitdisabled = true;
  123. target1 = player.transform;
  124. target = enemycheckpoint2.transform;
  125. enemyspeed = 0.8;
  126.  
  127.  
  128.  
  129. }
  130.  
  131. if(other.gameObject.tag == "Player")
  132. {
  133. currentState = ENEMY_STATE.STATE_FOLLOW;
  134.  
  135.  
  136. }
  137. else
  138. {
  139. return;
  140. }
  141. }
  142. function OnTriggerExit(other:Collider)
  143. {
  144. if(other.gameObject.tag == "Player")
  145. {
  146. currentState = ENEMY_STATE.STATE_MOVE;
  147. target = enemycheckpoint1.transform;
  148. target1 = enemycheckpoint1.transform;
  149. }
  150. else
  151. {
  152. return;
  153. }
  154. }
  155. function OnCollisionExit(theCollision:Collision)
  156. {
  157. if(theCollision.gameObject.tag == "ground")
  158. {
  159. if(exitdisabled ==false)
  160. {
  161. isgrounded = false;
  162. }
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment