56 lines
1.1 KiB
C#
56 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using TMPro;
|
|
|
|
public class ToastTip : MonoBehaviour
|
|
{
|
|
//文字信息
|
|
public Text txtInfo;
|
|
//上移速度
|
|
public float moveSpeed;
|
|
//隐藏速度
|
|
public float hideSpeed;
|
|
//位置
|
|
public RectTransform rec;
|
|
//透明组件
|
|
public CanvasGroup can;
|
|
//记录时间
|
|
private float addTime;
|
|
//起始点
|
|
private Vector2 startPos;
|
|
|
|
private void OnEnable()
|
|
{
|
|
can.alpha = 1;
|
|
startPos = rec.localPosition;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
addTime += Time.deltaTime;
|
|
startPos.y += Time.deltaTime * moveSpeed;
|
|
rec.localPosition = startPos;
|
|
if (startPos.y >= 300f)
|
|
{
|
|
startPos.y = 300f;
|
|
}
|
|
|
|
if (addTime >= 1.5f)
|
|
{
|
|
can.alpha -=Time.deltaTime * hideSpeed;
|
|
if (can.alpha<=0)
|
|
{
|
|
can.alpha = 0;
|
|
addTime = 0;
|
|
rec.position=Vector3.zero;
|
|
PoolMgr.Instance.PushObj(this.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateTxtInfo(string str)
|
|
{
|
|
txtInfo.text=str;
|
|
}
|
|
} |