|
using UnityEngine;
|
using System;
|
using UnityEngine.UI;
|
|
public class BattleTips : MonoBehaviour
|
{
|
public Vector2 beginPos = Vector2.zero;
|
public Vector2 endPos = new Vector2(0, 100);
|
public float showTime = 0.4f;
|
public float timer = 0f;
|
|
public RectTransform rectTransform;
|
|
public Text tipText;
|
|
public Action OnFinish;
|
|
public void SetText(string text)
|
{
|
tipText.text = text;
|
rectTransform.anchoredPosition = Vector2.zero;
|
timer = 0f;
|
gameObject.SetActive(true);
|
}
|
|
|
// 不要使用update
|
public void Run()
|
{
|
if (!gameObject.activeSelf)
|
return;
|
|
if (timer >= showTime)
|
{
|
OnFinish?.Invoke();
|
OnFinish = null;
|
return;
|
}
|
|
rectTransform.anchoredPosition = Vector2.Lerp(beginPos, endPos, timer / showTime);
|
timer += Time.deltaTime;
|
}
|
}
|