68 lines
1.3 KiB
C#
68 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using TMPro;
|
|
|
|
public class AddGasNum : MonoBehaviour
|
|
{
|
|
//文字信息
|
|
public Text txtInfo;
|
|
//上移速度
|
|
public float moveSpeed;
|
|
//向上偏移位置
|
|
public float moveOffset;
|
|
//隐藏速度
|
|
public float hideSpeed;
|
|
//位置
|
|
public RectTransform rec;
|
|
//透明组件
|
|
public CanvasGroup can;
|
|
//起始点
|
|
private Vector2 startPos;
|
|
|
|
private void OnEnable()
|
|
{
|
|
can.alpha = 1;
|
|
startPos = rec.localPosition;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (GameMgr.Instance.isUserNumAndGas)
|
|
{
|
|
ResetData();
|
|
return;
|
|
}
|
|
startPos.y += Time.deltaTime * moveSpeed;
|
|
if (startPos.y >= moveOffset)
|
|
{
|
|
startPos.y = moveOffset;
|
|
}
|
|
else
|
|
{
|
|
rec.localPosition = startPos;
|
|
}
|
|
|
|
if (startPos.y >= 100f)
|
|
{
|
|
can.alpha -= Time.deltaTime * hideSpeed;
|
|
if (can.alpha <= 0)
|
|
{
|
|
ResetData();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateTxtInfo(string str)
|
|
{
|
|
txtInfo.text=str;
|
|
}
|
|
|
|
//重置数据并放入对象池内
|
|
public void ResetData()
|
|
{
|
|
can.alpha = 0;
|
|
rec.position = Vector3.zero;
|
|
PoolMgr.Instance.PushObj(this.gameObject);
|
|
}
|
|
} |