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

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

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{
09gui.pixelInset.xMax = originalPixelRect.xMin+ stream.progress * originalPixelRect.width;
10yield;
11}
12// Update it one last time before loading
13gui.pixelInset.xMax = originalPixelRect.xMax;
14stream.LoadUnityWeb();
15}
16@script RequireComponent (GUITexture)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值