| 
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; 
 | 
    } 
 | 
} 
 |