Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyAI : MonoBehaviour
  6. {
  7. public int enemyhealth;
  8. public int energy;
  9. public float distance;
  10. public float waitforaction;
  11. public int act;
  12. public int attackact;
  13. public int range;
  14. public GameObject player;
  15.  
  16. public int playerevade;
  17. public int accuracy;
  18. public int accuracyhalf;
  19.  
  20. //attacks
  21. public int attackoneaccuracy;
  22. //chance to hit
  23. public int attackcost;
  24. //energy lost
  25. public int attackonedamage;
  26. //damage to player
  27. public int attackoneenergy;
  28. //if enemy energy is gained
  29. public int attackonechangehealth;
  30. //if enemy health is gained
  31. public int changeactone;
  32. //if enemy attack time is changed
  33.  
  34. public int attacktwoaccuracy;
  35. public int attackcosttwo;
  36. public int attacktwodamage;
  37. public int attacktwoenergy;
  38. public int attacktwochangehealth;
  39. public int changeacttwo;
  40.  
  41. public int attackthreeaccuracy;
  42. public int attackcostthree;
  43. public int attackthreedamage;
  44. public int attackthreeenergy;
  45. public int attackthreechangehealth;
  46. public int changeacthree;
  47.  
  48.  
  49. void Start ()
  50. {
  51. player = GameObject.Find("Pigobj");
  52. StartCoroutine("action");
  53. }
  54. IEnumerator action ()
  55. {
  56. act = Random.Range (0, 10);
  57. if (act == 1 && energy > 0)
  58. {
  59. act = 0;
  60. StartCoroutine("right");
  61. }
  62. if (act == 2 && energy > 0)
  63. {
  64. act = 0;
  65. StartCoroutine("left");
  66. }
  67. if (act == 3 && energy > 0)
  68. {
  69. act = 0;
  70. StartCoroutine("up");
  71. }
  72. if (act == 4 && energy > 0)
  73. {
  74. act = 0;
  75. StartCoroutine("down");
  76. }
  77. if (act >= 5 && energy > 0)
  78. {
  79. act = 0;
  80. StartCoroutine("attack");
  81. }
  82. yield return new WaitForSeconds(waitforaction);
  83. StartCoroutine("action");
  84. }
  85. IEnumerator right ()
  86. {
  87. energy -= 1;
  88. this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (distance, 0.0f, 0.0f);
  89. yield return new WaitForSeconds(2);
  90. }
  91. IEnumerator left ()
  92. {
  93. energy -= 1;
  94. this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (-distance, 0.0f, 0.0f);
  95. yield return new WaitForSeconds(2);
  96. }
  97. IEnumerator up ()
  98. {
  99. energy -= 1;
  100. this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (0.0f, 0.0f, distance);
  101. yield return new WaitForSeconds(2);
  102. }
  103. IEnumerator down ()
  104. {
  105. energy -= 1;
  106. this.gameObject.transform.position = this.gameObject.transform.position + new Vector3 (0.0f, 0.0f, -distance);
  107. yield return new WaitForSeconds(2);
  108. }
  109. IEnumerator attack ()
  110. {
  111. if (Vector3.Distance (player.transform.position, this.gameObject.transform.position) < range)
  112. {
  113. attackact = Random.Range (0, 3);
  114. if (attackact == 1)
  115. {
  116. StartCoroutine("attackone");
  117. }
  118. if (attackact == 2)
  119. {
  120. StartCoroutine("attacktwo");
  121. }
  122. if (attackact == 3)
  123. {
  124. StartCoroutine("attackthree");
  125. }
  126. }
  127. yield return new WaitForSeconds(2);
  128. }
  129.  
  130. //add evade option
  131. IEnumerator attackone ()
  132. {
  133. energy -= attackcost;
  134. playerevade = GameObject.Find ("Pigobj").GetComponent<Master>().evade;
  135. accuracyhalf = playerevade / 2;
  136. accuracy = Random.Range (playerevade, attackoneaccuracy);
  137. if (playerevade < accuracyhalf)
  138. {
  139. GameObject.Find("Pigobj").GetComponent<Master>().currenthealth -= attackonedamage;
  140. enemyhealth += attackonechangehealth;
  141. energy += attackoneenergy;
  142. waitforaction = changeactone;
  143. yield return new WaitForSeconds(2);
  144. }
  145. }
  146. IEnumerator attacktwo ()
  147. {
  148. energy -= attackcosttwo;
  149. playerevade = GameObject.Find ("Pigobj").GetComponent<Master>().evade;
  150. accuracyhalf = playerevade / 2;
  151. accuracy = Random.Range (playerevade, attacktwoaccuracy);
  152. if (accuracy < accuracyhalf)
  153. {
  154. GameObject.Find("Pigobj").GetComponent<Master>().currenthealth -= attacktwodamage;
  155. enemyhealth += attacktwochangehealth;
  156. energy += attacktwoenergy;
  157. waitforaction = changeacttwo;
  158. yield return new WaitForSeconds(2);
  159. }
  160. }
  161. IEnumerator attackthree ()
  162. {
  163. energy -= attackcostthree;
  164. playerevade = GameObject.Find ("Pigobj").GetComponent<Master>().evade;
  165. accuracyhalf = playerevade / 2;
  166. accuracy = Random.Range (playerevade, attackthreeaccuracy);
  167. if (accuracy < accuracyhalf)
  168. {
  169. GameObject.Find("Pigobj").GetComponent<Master>().currenthealth -= attackthreedamage;
  170. enemyhealth += attackthreechangehealth;
  171. energy += attackthreeenergy;
  172. waitforaction = changeacthree;
  173. yield return new WaitForSeconds(2);
  174. }
  175. }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement