HUD.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Collections;
  5. public class HUD : ObjectPoolRoot
  6. {
  7. #region 变量
  8. private float StayTimer;
  9. private Text Text;
  10. [NonSerialized] public float Speed;
  11. [NonSerialized] public float _StayTime;
  12. [NonSerialized] public bool Permanent;
  13. #endregion
  14. private void Awake()
  15. {
  16. Text = GetComponent<Text>();
  17. ObjectPoolType = ObjectPoolType.HUD;
  18. }
  19. private void OnEnable()
  20. {
  21. Text.color = new Color(Text.color.r, Text.color.g, Text.color.b, 1);
  22. StayTimer = _StayTime;
  23. }
  24. private void FixedUpdate()
  25. {
  26. if (Permanent)
  27. {
  28. return;
  29. }
  30. StayTimer -= Time.fixedDeltaTime;
  31. if (StayTimer <= 0)
  32. {
  33. transform.Translate(Vector3.up*Speed, Space.World);
  34. Color color = Text.color;
  35. color.a = Mathf.Lerp(color.a, 0, Time.fixedDeltaTime * 2);
  36. if (color.a <= 0.05f)
  37. {
  38. ManagerResource.Ins.Save(gameObject);
  39. }
  40. Text.color = color;
  41. }
  42. }
  43. public void Set(Color color, bool isPermanent, string message, float speed, float stayTime)
  44. {
  45. Text.text = message;
  46. Text.color = color;
  47. Speed = speed;
  48. Permanent = isPermanent;
  49. _StayTime = stayTime;
  50. }
  51. }