美文网首页unity3D技术分享Unity教程合集
unity3d UGUI常用游戏进度条实现方式

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

作者: 好怕怕 | 来源:发表于2017-04-14 10:44 被阅读964次
测试.png

直接将脚本挂载到进度条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;
    }
}

相关文章

网友评论

    本文标题:unity3d UGUI常用游戏进度条实现方式

    本文链接:https://www.haomeiwen.com/subject/ikrwattx.html