ManaMessage.cs 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public class ManaMessage : MonoBehaviour
  5. {
  6. #region 变量
  7. private static float StayTimer;
  8. private static Text MessageLab;
  9. #endregion
  10. private void Awake()
  11. {
  12. MessageLab = ManaReso.Get<Text>("Message");
  13. }
  14. private void FixedUpdate()
  15. {
  16. if (MessageLab.color.a > 0)
  17. {
  18. StayTimer -= Time.fixedDeltaTime;
  19. if (StayTimer > 0)
  20. {
  21. return;
  22. }
  23. MessageLab.SetAlpha(Mathf.Lerp(MessageLab.color.a, 0, Time.fixedDeltaTime));
  24. if (MessageLab.color.a <= 0.05f)
  25. {
  26. MessageLab.SetAlpha(0);
  27. }
  28. }
  29. }
  30. public static void Show(string message, float stayTime)
  31. {
  32. MessageLab.text = message;
  33. MessageLab.SetAlpha(1);
  34. StayTimer = stayTime;
  35. }
  36. }