CoreCharacter.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. public class CoreCharacter : Character
  6. {
  7. [Header("传送门核心")]
  8. public float totalTime = 10;
  9. [HideInInspector]
  10. public float time;
  11. [HideInInspector]
  12. public string Text;
  13. public TextMeshProUGUI[] countDown = new TextMeshProUGUI[2];
  14. public bool isCoutDown; //是否开始倒计时
  15. public GameObject[] portals = new GameObject[2];
  16. public GameObject enemyUI;
  17. private void Update()
  18. {
  19. if (isCoutDown)
  20. {
  21. time -= Time.deltaTime;
  22. Text = ((int)time + 1).ToString();
  23. foreach(TextMeshProUGUI text in countDown)
  24. {
  25. text.text = Text;
  26. }
  27. if (time < 0)
  28. {
  29. PortalsDisappear();
  30. }
  31. }
  32. }
  33. public override void BeHit(int damage)
  34. {
  35. hp -= damage;
  36. uiHp.Show(hp, totalHp);
  37. if (hp <= 0)
  38. {
  39. CoreBreak();
  40. return;
  41. }
  42. }
  43. //核心被打破
  44. public void CoreBreak()
  45. {
  46. bodyTrans.gameObject.SetActive(false);
  47. uiHp.gameObject.SetActive(false);
  48. enemyUI.SetActive(false);
  49. for (int i = 0; i < countDown.Length; i++)
  50. {
  51. if (portals[i].transform.localScale.x < 0)
  52. {
  53. Vector3 localScale = countDown[i].transform.localScale;
  54. localScale.x = -localScale.x;
  55. }
  56. countDown[i].gameObject.SetActive(true);
  57. }
  58. time = totalTime;
  59. isCoutDown = true;
  60. }
  61. public void PortalsDisappear()
  62. {
  63. foreach(GameObject portal in portals)
  64. {
  65. portal.SetActive(false);
  66. }
  67. }
  68. }