ESpirits_Cook.cs 3.6 KB

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