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

Unity3D 动态显示场景跳转提示框

2013-05-09 16:03 309 查看
#pragma strict

//Author:Andy Sun

//Time:2013/4/16

//Function:Load a new scene

var newScene:String;//The Scene that will be Loaded

var sceneView:Texture2D;//The view image the loaded scene

private var firstPersonPlayer:GameObject;

private var label_width_Max:float;//The max width of the Label

private var label_height_Max:float;//The max height of the Label

private var label_width:float=0.0f;//The width of the Label

private var label_height:float=0.0f;//The height of the Label

private var showPrompt:boolean=false;

private var script:Follow_Load;//Get the Script Object

private var enter:boolean=false;//If the Player Enter the Trigger

function Start () {

if(GameObject.FindWithTag("Manager")){

firstPersonPlayer = GameObject.FindWithTag("Manager");

script = firstPersonPlayer.GetComponent(Follow_Load);

}

}

function Update () {

label_width_Max = Screen.width/3;

label_height_Max = Screen.height/3;

if(label_width<label_width_Max && showPrompt){

label_width += label_width_Max*0.05;

}

if(label_height<label_height_Max && showPrompt){

label_height += label_height_Max*0.05;

}

if(!showPrompt && (label_width>0.0f)){

label_width-=label_width_Max*0.05;

}

if(!showPrompt && (label_height>0.0f)){

label_height-=label_height_Max*0.05;

}

}

function OnGUI()

{

//if the distance is less than 1.0f,show the prompt

if(enter){

showPrompt = true;

GUI.DrawTexture(new Rect(Screen.width/2-label_width/2,Screen.height/2-label_height/2,label_width,label_height),sceneView,ScaleMode.StretchToFill,true,10.0f);

if(GUI.Button(new Rect(Screen.width/2-label_width/6,Screen.height/2+label_height/2-label_height/5,label_width/3,label_height/10),"进入/"+""+newScene))

{

script.Load_Level(newScene);//Load a new Scene

}

}else{//if the distance is more than 5.0f,clear away the prompt

showPrompt = false;

GUI.DrawTexture(new Rect(Screen.width/2-label_width/2,Screen.height/2-label_height/2,label_width,label_height),sceneView,ScaleMode.StretchToFill,true,10.0f);

}

}

function OnTriggerEnter (other : Collider) {

enter=true;

}

function OnTriggerExit (other : Collider) {

enter=false;

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