GameUI.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. public class GameUI : MonoBehaviour
  7. {
  8. public static GameUI instance;
  9. public Animator player_is_hurt;
  10. public Image half_hp;
  11. public AnimationClip player_is_hurt_animaton;
  12. public Transform CD;
  13. public TextMeshProUGUI summonNum;
  14. private float hurtClipTime;
  15. private float hurtTime;
  16. private bool isHurt;
  17. private float hpRate;
  18. private float lastDyingTime;
  19. private void Awake()
  20. {
  21. if (!instance)
  22. {
  23. instance = this;
  24. }
  25. hurtClipTime = player_is_hurt_animaton.length;
  26. }
  27. private void Update()
  28. {
  29. if (isHurt)
  30. {
  31. hurtTime += Time.deltaTime;
  32. if(hurtTime >= hurtClipTime)
  33. {
  34. isHurt = false;
  35. if (hpRate >= 0.2f)
  36. {
  37. player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_ok, 0, 0);
  38. }
  39. else
  40. {
  41. player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_dying, 0, lastDyingTime);
  42. }
  43. }
  44. }
  45. }
  46. public void HurtMask(float hpRate)
  47. {
  48. AnimatorStateInfo stateInfo = player_is_hurt.GetCurrentAnimatorStateInfo(0);
  49. if(stateInfo.shortNameHash != AnimatorHash.ANIMATOR_player_is_hurt)
  50. {
  51. lastDyingTime = player_is_hurt.GetCurrentAnimatorStateInfo(0).normalizedTime;
  52. }
  53. player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_hurt, 0, 0);
  54. half_hp.color = new Color(0, 0, 0, (0.6f - hpRate) * 2);
  55. this.hpRate = hpRate;
  56. hurtTime = 0;
  57. isHurt = true;
  58. }
  59. }