您的位置:首页 > 移动开发 > Unity3D

Unity3D技术之进度条制作

2015-02-12 11:52 239 查看
我们都知道玩游戏时,第一步要加载游戏,加载游戏时我们可以做一个简单的进度条来显示游戏加载进度,应为有了进度条,游戏画面不会过于呆板。
那么我们就开始游戏的进度条制作吧!本文章出自【狗刨网】
方法一:
 
1、使用NGUI制作,首先将NGUI插件导入到Unity 工程中。
导入后:
 

 

2、创建UI

 

 

3、在Panel下添加slider。

 

 

4、此处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;    }}

 
准备工作好了,运行效果:
 
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: