NG_/Assets/Scripts/UI/工具栏/TextFollowingFill.cs
2024-12-13 19:40:05 +08:00

27 lines
645 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// 文字根据图片填充更新位置
public class TextFollowingFill : MonoBehaviour
{
public Image progressImage;
public float padding = 10f;
private RectTransform textLabel;
void Start()
{
textLabel = GetComponent<RectTransform>();
}
void Update()
{
float fillAmount = progressImage.fillAmount;
float targetX = progressImage.rectTransform.rect.width * fillAmount;
textLabel.anchoredPosition = new Vector2(targetX + padding, textLabel.anchoredPosition.y);
}
}