unity3d UGUI常用游戏进度条实现方式

unity3d UGUI常用游戏进度条实现方式_第1张图片
测试.png

直接将脚本挂载到进度条image对象上即可,这种方式可以解决当进度条使用图片的时候,防止图片拉伸变形

using UnityEngine;
using UnityEngine.UI;

/// 
/// 设置UI上image的进度条
/// 
public class NewProgressBar : MonoBehaviour
{
    private bool isInit = false;
    private Image progressBar;
    public  void Awake()
    {
        progressBar = transform.GetComponent();
        progressBar.type = Image.Type.Filled;
        progressBar.fillMethod = Image.FillMethod.Horizontal;
        progressBar.fillOrigin = 0;
    }

    public void SetProgressValue(float value)
    {
        progressBar.fillAmount = value;
    }
}

你可能感兴趣的:(unity3d UGUI常用游戏进度条实现方式)