hch
5 天以前 0fc013dc8d4d503ac5312512f805c7350f4f68f7
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 
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 Text artText;
 
    public Action OnFinish;
 
    public void SetText(string text, bool useArtText = false)
    {
        rectTransform.anchoredPosition = Vector2.zero;
        timer = 0f;
        gameObject.SetActive(true);
 
        if (useArtText)
        {
            artText.text = text;
            tipText.gameObject.SetActive(false);
            artText.gameObject.SetActive(true);
        }
        else
        {
            tipText.text = text;
            artText.gameObject.SetActive(false);
            tipText.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;
    }
}