| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- public class GameUI : MonoBehaviour
- {
- public static GameUI instance;
- public Animator player_is_hurt;
- public Image half_hp;
- public AnimationClip player_is_hurt_animaton;
- public Transform CD;
- public TextMeshProUGUI summonNum;
- private float hurtClipTime;
- private float hurtTime;
- private bool isHurt;
- private float hpRate;
- private float lastDyingTime;
- private void Awake()
- {
- if (!instance)
- {
- instance = this;
- }
- hurtClipTime = player_is_hurt_animaton.length;
- }
- private void Update()
- {
- if (isHurt)
- {
- hurtTime += Time.deltaTime;
- if(hurtTime >= hurtClipTime)
- {
- isHurt = false;
- if (hpRate >= 0.2f)
- {
- player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_ok, 0, 0);
- }
- else
- {
- player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_dying, 0, lastDyingTime);
- }
- }
- }
- }
- public void HurtMask(float hpRate)
- {
- AnimatorStateInfo stateInfo = player_is_hurt.GetCurrentAnimatorStateInfo(0);
- if(stateInfo.shortNameHash != AnimatorHash.ANIMATOR_player_is_hurt)
- {
- lastDyingTime = player_is_hurt.GetCurrentAnimatorStateInfo(0).normalizedTime;
- }
- player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_hurt, 0, 0);
- half_hp.color = new Color(0, 0, 0, (0.6f - hpRate) * 2);
- this.hpRate = hpRate;
- hurtTime = 0;
- isHurt = true;
- }
- }
|