Unity 3D 進度條制作


我們都知道玩游戲時,第一步要加載游戲,加載游戲時我們可以做一個簡單的進度條來顯示游戲加載進度,應為有了進度條,游戲畫面不會過於呆板。

那么我們就開始游戲的進度條制作吧!

方法一:

1,使用NGUI制作,首先將NGUI插件導入到Unity 工程中。

導入后:

2,創建UI

3,在Panel下添加slider。

此處label是為了顯示游戲進度。

5,腳本Procebar.cs,將此腳本添加到slider上。

using UnityEngine;
using System.Collections;
using System.Collections.Generic;


public class DrawLine : MonoBehaviour
{
    private List<GameObject>line;
    public GameObject prbCube;
    public Vector2 vect2;
    public static int tmp_x;
    public UILabel label1;
    private string str;
    private int tmp_num;
    
    // Use this for initialization
    void Start () 
    {
        tmp_x=0;
        tmp_num=0;
        str="加載游戲:";
        line=new List<GameObject>();
        InvokeRepeating("CreateLine",0,0.167f);
    }
    
    
    // Update is called once per frame
    void Update () 
    {
        
    }


    /// <summary>
    /// 進度條
    /// </summary>
    void CreateLine()
    {
        if(OverButton.IsOnButton)
        {
            if(line.Count<=20)
            {
                tmp_num=line.Count;
                GameObject tmp=Instantiate(prbCube)as GameObject;
                tmp.transform.localPosition=new Vector3(((float)line.Count/10-2f)+1.2f,0.8f,0);
                line.Add(tmp);
            }
        }
        else
        {
            foreach(GameObject i in line)
            {
                Destroy(i);
            }
            tmp_num=0;
            line.Clear();
        }
    }
    
    
    /// <summary>
    /// 顯示進度
    /// </summary>
    void OnGUI()
    {
        label1.text=str+(tmp_num*5).ToString()+"/100";
        label1.color=Color.yellow;
    }
}
View Code

准備工作好了,運行效果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM