ESpirits_Cook.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. using System;
  6. public class ESpirits_Cook : MonoBehaviour
  7. {
  8. public TextMeshProUGUI text; //剩余串的数量文本
  9. private GameObject dia; //文本框
  10. private Transform cook; //厨子
  11. private Animator ani; //厨子动画
  12. private Collider col; //厨子的碰撞体
  13. public int chuan; //厨子拥有多少串
  14. public bool isGood; //厨子是否是好厨子
  15. public GameObject[] colliders; //一些要开要关的collider
  16. public float walkSpeed; //走路速度
  17. public float runSpeed; //冲刺速度
  18. public float minX; //厨子卖串的最小地址站
  19. public float maxX; //厨子卖串的最大地址站
  20. public float value; //加血程度百分比
  21. public GameObject effect; //加血效果
  22. private Enemy ene; //厨子的enemy脚本
  23. private bool once = false; //死一次
  24. private bool die = false; //厨子命尽
  25. private bool toCatch = false; //没串了去抓人
  26. private bool isRunning = false; //开跑
  27. private float activeTime; //厨子已出现的时长
  28. public float activeAniTime; //厨子出现动画的时长
  29. private bool isAct = false; //厨子已经完整出现
  30. private GameObject[] customers; //厨子的所有顾客
  31. private int count; //顾客数量
  32. public float larger; //顾客变大的程度
  33. public bool canMove = false; //厨师可移动
  34. private GameObject player1;
  35. private GameObject player2;
  36. private GameObject target;
  37. public GameObject lockEffect;
  38. private GameObject curLock;
  39. public enum cookState
  40. {
  41. sell = 0,
  42. walk = 1,
  43. find = 2,
  44. run = 3,
  45. cook = 4,
  46. back = 5,
  47. }
  48. private cookState state;
  49. private GameObject food; //被抓的食材
  50. private void Start()
  51. {
  52. cook = transform.parent;
  53. ene = cook.GetComponent<Enemy>();
  54. ani = ene.ani;
  55. col = GetComponent<Collider>();
  56. col.enabled = false;
  57. dia = text.transform.parent.gameObject;
  58. dia.SetActive(false);
  59. customers = new GameObject[chuan];
  60. state = 0;
  61. curLock = Instantiate(lockEffect, cook.transform.position, new Quaternion(0, 0, 0, 0), cook.transform);
  62. }
  63. private void OnTriggerEnter(Collider other)
  64. {
  65. //路过发串
  66. if (state == cookState.sell && !die && other.gameObject.layer == 7 || other.gameObject.layer == 8 || other.gameObject.layer == 6)
  67. {
  68. if (chuan > 0)
  69. {
  70. GameObject ga = other.transform.parent.parent.parent.gameObject;
  71. Character ca = ga.GetComponent<Character>();
  72. if (Array.IndexOf(customers, ga) == -1)
  73. {
  74. chuan -= 1;
  75. text.text = chuan.ToString();
  76. ani.Play("attack_march", 0, 0);
  77. ca.HpUp(value, larger);
  78. customers[count] = ga;
  79. count += 1;
  80. Instantiate(effect, ga.transform.position, new Quaternion(0, 0, 0, 0), ga.transform);
  81. if (chuan == 0)
  82. {
  83. toCatch = true;
  84. ChangeState(cookState.walk);
  85. }
  86. }
  87. }
  88. }
  89. //抓人
  90. else if (state == cookState.run || state == cookState.find || state == cookState.walk && !once)
  91. {
  92. if (other.gameObject.layer == 7 || other.gameObject.layer == 6)
  93. {
  94. food = other.gameObject;
  95. ChangeState(cookState.cook);
  96. }
  97. }
  98. }
  99. private void ChangeState(cookState cs)
  100. {
  101. switch (cs)
  102. {
  103. //卖串中
  104. case cookState.sell:
  105. canMove = false;
  106. //不能被攻击
  107. foreach (GameObject g in colliders)
  108. {
  109. g.SetActive(false);
  110. }
  111. break;
  112. //走路中
  113. case cookState.walk:
  114. canMove = true;
  115. dia.SetActive(false);
  116. //能被攻击
  117. foreach (GameObject g in colliders)
  118. {
  119. g.SetActive(true);
  120. }
  121. break;
  122. //发现目标
  123. case cookState.find:
  124. break;
  125. //冲刺中
  126. case cookState.run:
  127. canMove = true;
  128. foreach (GameObject g in colliders)
  129. {
  130. g.SetActive(true);
  131. }
  132. break;
  133. //鲨人中
  134. case cookState.cook:
  135. break;
  136. //返回中
  137. case cookState.back:
  138. break;
  139. default:
  140. break;
  141. }
  142. state = cs;
  143. }
  144. private void ChoosePlayer()
  145. {
  146. player1 = PlayersInput.instance[0].gameObject;
  147. player2 = PlayersInput.instance[1].gameObject;
  148. float dis1 = Vector2.Distance(player1.transform.position, transform.position);
  149. float dis2 = Vector2.Distance(player2.transform.position, transform.position);
  150. if (dis1 < dis2)
  151. {
  152. target = player1;
  153. }
  154. else
  155. {
  156. target = player2;
  157. }
  158. }
  159. private void AimAtPlayer()
  160. {
  161. lockEffect.transform.position = transform.position;
  162. }
  163. private void StateAct(cookState cs)
  164. {
  165. switch (cs)
  166. {
  167. case cookState.walk:
  168. break;
  169. case cookState.find:
  170. break;
  171. case cookState.back:
  172. break;
  173. case cookState.cook:
  174. break;
  175. case cookState.run:
  176. ene.targetCharacter = target.GetComponent<Character>();
  177. break;
  178. case cookState.sell:
  179. break;
  180. default:
  181. break;
  182. }
  183. }
  184. private void Update()
  185. {
  186. if (!isAct)
  187. {
  188. activeTime += Time.deltaTime;
  189. if (activeTime >= activeAniTime)
  190. {
  191. dia.SetActive(true);
  192. isAct = true;
  193. col.enabled = true;
  194. }
  195. }
  196. if (die && !once)
  197. {
  198. once = true;
  199. col.enabled = false;
  200. ene.ChangeState(CharacterState.Die);
  201. }
  202. }
  203. }