LiftButtonComp.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using Game;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Comp
  6. {
  7. public class LiftButtonComp : MonoBehaviour
  8. {
  9. private Button _button;
  10. private void Start()
  11. {
  12. _button = GetComponent<Button>();
  13. }
  14. private void Update()
  15. {
  16. if (GameCore.Instance.localPlayer == null) return;
  17. var lastHpPercent = (float)GameCore.Instance.localPlayer.runTimeHp / GameCore.Instance.localPlayer.hp;
  18. if (GameCore.Instance.GetCurState() != null && GameCore.Instance.battleState != null &&
  19. GameCore.Instance.GetCurState() == GameCore.Instance.battleState && GameCore.Instance.liftTimes > 0 )
  20. {
  21. #if UNITY_EDITOR
  22. _button.interactable = true;
  23. #else
  24. if(lastHpPercent <= 0.5f){
  25. _button.interactable = true;
  26. } else {
  27. _button.interactable = false;
  28. }
  29. #endif
  30. }
  31. else
  32. {
  33. _button.interactable = false;
  34. }
  35. }
  36. }
  37. }