直接将脚本挂载到进度条image对象上即可,这种方式可以解决当进度条使用图片的时候,防止图片拉伸变形
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 设置UI上image的进度条
/// </summary>
public class NewProgressBar : MonoBehaviour
{
private bool isInit = false;
private Image progressBar;
public void Awake()
{
progressBar = transform.GetComponent<Image>();
progressBar.type = Image.Type.Filled;
progressBar.fillMethod = Image.FillMethod.Horizontal;
progressBar.fillOrigin = 0;
}
public void SetProgressValue(float value)
{
progressBar.fillAmount = value;
}
}