签到

07月13日
尚未签到

共有回帖数 0

    三寸海屿日光

    等级:


    实现功能:点击开始游戏以后UI界面进入Loading界面,Loading结束以后自动进入游戏场景。在这之前先在Build Settings中Add要使用的场景在场景
    A中添加StartGame方法:Application.LoadLevel(1);//同步加载Loading界面(因为Loading界面资源较少速度快所以此处用同步方法)
    在Loading场景中加入进度条图片:分为上下两层,上层负责显示进度


    接下来再Loading场景Cam中添加以下代码(通过改变Fill Amount显示Loading效果):public class Loading : MonoBehaviour {
    AsyncOperation asyncOperation; //声明一个异步变量
    public GameObject progress; //声明进度条对象
    public GameObject Text; //声明进度条上的显示文本 //对以上变量进行初始化 void Start()
    { progress.SetActive(true);
    progress = GameObject.FindWithTag("Fader");
    Text = GameObject.FindWithTag("Text");
    Text.GetComponentText().text = "0";
    progress.GetComponentImage().fillAmount = 0f;
    DontDestroyOnLoad(gameObject);
    StartCoroutine(loadScene()); //开启异步任务,进入loadScene方法
    }
    void Update()
    {
    Text.GetComponentText().text = (float)asyncOperation.progress*100+10+"%"; //文本更新异步进度
    progress.GetComponentImage().fillAmount = (float)asyncOperation.progress+.1f;//进度条更新异步进度
    }
    IEnumerator loadScene()
    {
    yield return asyncOperation = Application.LoadLevelAsync(2);//读取完毕自动进入下一个场景
    }

    }最终效果如下:


    楼主 2016-03-11 09:34 回复

共有回帖数 0
  • 回 帖
  • 表情 图片 视频
  • 发表

登录直线网账号

Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号 意见反馈 | 关于直线 | 版权声明 | 会员须知