ESpirits_Cook.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. using System;
  6. using Random = UnityEngine.Random;
  7. public class ESpirits_Cook : MonoBehaviour
  8. {
  9. public TextMeshProUGUI text; //剩余串的数量文本
  10. private GameObject dia; //文本框
  11. private Transform cook; //厨子
  12. private Animator ani; //厨子动画
  13. public int chuan; //厨子拥有多少串
  14. //public bool isGood; //厨子是否是好厨子
  15. private float intervalTimePast;
  16. public float intervalTimeSell; //卖串的间隔时间
  17. private bool isInterval = false; //开始计算间隔时间
  18. public float minX; //厨子卖串的最小地址站
  19. public float maxX; //厨子卖串的最大地址站
  20. public float value; //加血程度百分比
  21. public GameObject effect; //加血效果
  22. private Enemy ene; //厨子的enemy脚本
  23. private float activeTime; //厨子已出现的时长
  24. public float activeAniTime; //厨子出现动画的时长
  25. private bool isAct = false; //厨子已经完整出现
  26. public float larger; //顾客变大的程度
  27. public List<Character> customers; //所有顾客
  28. public Character target;
  29. public SearchTrigger searchtrigger;
  30. private float destX;
  31. private void Start()
  32. {
  33. cook = transform.parent;
  34. ene = cook.GetComponent<Enemy>();
  35. ani = ene.ani;
  36. dia = text.transform.parent.gameObject;
  37. destX = DestinationX();
  38. text.text = chuan.ToString();
  39. ene.noOnSearchState = true;
  40. dia.SetActive(false);
  41. }
  42. private float DestinationX()
  43. {
  44. float x = Random.Range(minX, maxX);
  45. return x;
  46. }
  47. private void TargetInteract()
  48. {
  49. target = searchtrigger.GetMinDisTarget(ene.targetTypes, ene.canHitFly);
  50. if (target != null)
  51. {
  52. if (target.gameObject.layer == 7 || target.gameObject.layer == 8 || target.gameObject.layer == 6)
  53. {
  54. if (!isInterval && chuan > 0)
  55. {
  56. if (!customers.Exists(T => T == target))
  57. {
  58. isInterval = true;
  59. chuan -= 1;
  60. text.text = chuan.ToString();
  61. ani.Play("attack_march", 0, 0);
  62. target.HpUp(value, larger);
  63. customers.Add(target);
  64. //count += 1;
  65. //Instantiate(effect, ga.transform.position, new Quaternion(0, 0, 0, 0), ga.transform);
  66. if (chuan == 0)
  67. {
  68. ene.ChangeState(CharacterState.Die);
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. private bool isMove = false;
  76. private void Update()
  77. {
  78. if (!isAct)
  79. {
  80. if (!isMove)
  81. {
  82. activeTime += Time.deltaTime;
  83. if (activeTime >= activeAniTime)
  84. {
  85. dia.SetActive(true);
  86. isMove = true;
  87. ene.canMove = true;
  88. }
  89. }
  90. else
  91. {
  92. if (transform.position.x >= destX)
  93. {
  94. dia.SetActive(true);
  95. ene.canMove = false;
  96. isMove = false;
  97. isAct = true;
  98. }
  99. }
  100. }
  101. if (isInterval)
  102. {
  103. intervalTimePast += Time.deltaTime;
  104. if (intervalTimePast >= intervalTimeSell)
  105. {
  106. intervalTimePast = 0;
  107. isInterval = false;
  108. }
  109. }
  110. }
  111. private void FixedUpdate()
  112. {
  113. if (isAct)
  114. {
  115. TargetInteract();
  116. }
  117. }
  118. }