`
lwp11411
  • 浏览: 21384 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

动态加载网上或者本地场景

 
阅读更多

中秋节在外,一个人无聊+无奈,幸而在朋友家里蹭了顿饭,顺便打发时间,在此感谢我的朋友。放假两天,睡了两天,今天开始上班,顺便写点东西。

01 var gui : GUITexture;
02 var find : GameObject;
03 var GameObjectName;
04 function Awake(){
05 //找到guiTexture,当初始加载时让其不可用
06    find=GameObject.Find("guiTexture");
07    find.active=false;
08    GameObjectName=GameObject.Find("Cube").tag;//通过tag来传递参数给www()函数
09 }
10   
11 function OnMouseDown(){
12    find.active=true;
13    //Debug.Log(GameObjectName);
14    var SenceName=GameObjectName;
15    www(SenceName);
16 }
17   
18 function www(Cubename){
19 // Store the original pixel inset
20 // and modify it from there.
21 var originalPixelRect = gui.pixelInset;
01 功能及使用说明:<BR>1、建立一个Cube,然后将这段代码加到Cube上。<BR>2、建立一个GUITexture,并命名为guiTexture,选择Texture。这个GUITexture主要是用作进度条的。<BR>功能:动态加载网上或者本地场景<BR>点击Cube,加载场景,等进度条不再变化时进入你想进入的场景,点击时Cube没有变化,希望大家可以完善它。<BR><BR>
02   
03 // Update the progress bar by scaling the gui texture
04 // until we reach the end
05 // var stream=new WWW("http://unity3d.com/gallery/hosted-demos/dressingroom.unity3d");本地连接官网上的例子
06 var stream=new WWW(""+Cubename+".unity3d");//CubeName为你将要下载的场景名字
07 while (!stream.isDone)
08 {
09 gui.pixelInset.xMax = originalPixelRect.xMin+ stream.progress * originalPixelRect.width;
10 yield;
11 }
12 // Update it one last time before loading
13 gui.pixelInset.xMax = originalPixelRect.xMax;
14 stream.LoadUnityWeb();
15 }
16 @script RequireComponent (GUITexture)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics