123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using DG;
- using DG.Tweening;
- public class Fluter : MonoBehaviour
- {
- /// <summary>
- /// 生命周期时间
- /// </summary>
- public float liveTime;
- /// <summary>
- /// 当前运行时间
- /// </summary>
- private float _runTime;
- private bool _isEnable = false;
- /// <summary>
- /// 显示内容
- /// </summary>
- private string _content = "";
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (!_isEnable)
- {
- return;
- }
- this._runTime += Time.deltaTime;
- if (this._runTime > this.liveTime)
- {
- FluterManager.Instance.RemoveFluter(this);
- GameObject.Destroy(this.gameObject);
- }
- }
- /// <summary>
- /// 重设内容 时间恢复
- /// </summary>
- /// <param name="str"></param>
- public void RestContent(string str)
- {
- this._content = str;
- this.GetComponent<Text>().text = this._content;
- this.Play();
- }
- public void Play()
- {
- this._runTime = 0;
- Vector3 targetPos = this.transform.position;
- targetPos.x += Random.Range(-100, 100);
- targetPos.y += 100;
- this.transform.DOMove(targetPos, 1);
- Color color = Color.white;
- color.a = 0.3f;
- this.GetComponent<Text>().DOColor(color, 2);
- this._isEnable = true;
- }
- }
|