Fluter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using DG;
  6. using DG.Tweening;
  7. public class Fluter : MonoBehaviour
  8. {
  9. /// <summary>
  10. /// 生命周期时间
  11. /// </summary>
  12. public float liveTime;
  13. /// <summary>
  14. /// 当前运行时间
  15. /// </summary>
  16. private float _runTime;
  17. private bool _isEnable = false;
  18. /// <summary>
  19. /// 显示内容
  20. /// </summary>
  21. private string _content = "";
  22. // Start is called before the first frame update
  23. void Start()
  24. {
  25. }
  26. // Update is called once per frame
  27. void Update()
  28. {
  29. if (!_isEnable)
  30. {
  31. return;
  32. }
  33. this._runTime += Time.deltaTime;
  34. if (this._runTime > this.liveTime)
  35. {
  36. FluterManager.Instance.RemoveFluter(this);
  37. GameObject.Destroy(this.gameObject);
  38. }
  39. }
  40. /// <summary>
  41. /// 重设内容 时间恢复
  42. /// </summary>
  43. /// <param name="str"></param>
  44. public void RestContent(string str)
  45. {
  46. this._content = str;
  47. this.GetComponent<Text>().text = this._content;
  48. this.Play();
  49. }
  50. public void Play()
  51. {
  52. this._runTime = 0;
  53. Vector3 targetPos = this.transform.position;
  54. targetPos.x += Random.Range(-100, 100);
  55. targetPos.y += 100;
  56. this.transform.DOMove(targetPos, 1);
  57. Color color = Color.white;
  58. color.a = 0.3f;
  59. this.GetComponent<Text>().DOColor(color, 2);
  60. this._isEnable = true;
  61. }
  62. }