- Home /
loading problem
I have a script that creates 2 GUI buttons (one LOAD and the other New Game)...how can i get the file to load ? my problem is that im calling a "function LoadXML()" inside another function "OnGUI" butI dont know how to make the function LoadXML() work once activated ....
the code is:
var shownewgame : boolean = false;
var showcontinue : boolean = false;
var levelToLoad : String;
var soundhover : AudioClip;
var beep : AudioClip;
var QuitButton : boolean = false;
function OnMouseEnter(){
audio.PlayOneShot(soundhover);
}
function OnMouseUp(){
animation.CrossFade("PlayButtonAnimation");
audio.PlayOneShot(beep);
yield new WaitForSeconds(0.1);
if(QuitButton){
Application.Quit();
}
shownewgame = true;
showcontinue = true;
}
function Update(){}
function OnGUI(){
if(shownewgame == true){
if(GUI.Button(Rect(0,40,200,30),"New Game")){
Application.LoadLevel(levelToLoad); //Code for new game button
}
}
if(showcontinue == true){
if(GUI.Button(Rect(0,80,200,30),"Continue")){
//Code for continue button
function LoadXML()
{
//StreamReader r = File.OpenText(_FileLocation+"\\"+ _FileName);
var r : StreamReader = File.OpenText(_FileLocation+"/"+ _FileName);
var _info : String = r.ReadToEnd();
r.Close();
_data=_info;
Debug.Log("File Read");
}//Code for continue button
}
}
}
@script RequireComponent(AudioSource)
Answer by DaveA · Apr 07, 2012 at 07:58 AM
First, don't put the word 'function' here:
function LoadXML()
You put that whole function definition elsewhere outside OnGUI, and call it just LoadXML().
Second, I hope that's a coroutine or launches a thread or something, because if it blocks, it's going to mess with your GUI experience.
it launches a scene ,and how can still activate the function after the GUI button is pressed
Your answer
Follow this Question
Related Questions
[SOLVED]Static Loading screen help 0 Answers
Making a Gui Texture Continue To Rotate While Loading a Level 1 Answer
disable GUI when loading is done 5 Answers
disable code when level is rendered 1 Answer
Howt to Replace uGUI with asset bundles 0 Answers