yyl
2025-09-04 cdf7098c937c5f4a70383ef70897bf9fedbb3d99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
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;
    }
}