- Home /
Webplayer Stream problem
Hello, I have a java script that acts as my menu in game, The game build is a Webplayer "Streamed"
I want the script to display a GUItexture and disable the menu while the scene is being loaded and then load into the scene once its 100%
The first part of the script works but nothing happens after the else{ statement
if(GUI.Button (Rect ((Screen.width/2)-350,(Screen.height/2)-100,80,20), "Play")) {
if (Application.GetStreamProgressForLevel(1) == 1)
Application.LoadLevel ("Scene");
else {
percentageLoaded = Application.GetStreamProgressForLevel(1) * 100;
GetComponent(GUITexture).enabled = true;
GetComponent(MainMenu).enabled = false;
guiText.text = percentageLoaded.ToString();
}
}
Answer by Bunny83 · May 16, 2012 at 11:16 PM
I guess you want it like this:
function Start()
{
GetComponent(GUITexture).enabled = true;
GetComponent(MainMenu).enabled = false;
}
function OnGUI()
{
if (Application.GetStreamProgressForLevel(1) == 1)
{
if(GUI.Button (Rect ((Screen.width/2)-350,(Screen.height/2)-100,80,20), "Play"))
{
Application.LoadLevel ("Scene");
}
}
else
{
percentageLoaded = Application.GetStreamProgressForLevel(1) * 100;
guiText.text = percentageLoaded.ToString();
}
}
This will display your GUITexture while the progress is below 1.0 and when it's fully loaded, show the GUI.Button to load the level.
You might want to disable your GUITexture and the GUIText once the level is loaded...
Thanks what you added kind of showed me the way, I got the GUItexture to enable and the menu to disable AFTER i have pressed the "Play" button, The GUItexture is a loading screen image so i want that to display untill the next scene has fully streamed to 100% and then to automatically load the next scene, The problem im having is, Without me pressing the Play button, the game will just start anyway once its 100%, So how do i get it to wait untill i have pressed play before loading the scene? Here is were i am at the moment
if(GUI.Button (Rect ((Screen.width/2)-350,(Screen.height/2)-100,80,20), "Play")) {
if (Application.GetStreamProgressForLevel(1) == 1)
GetComponent(GUITexture).enabled = true;
GetComponent($$anonymous$$ain$$anonymous$$enu).enabled = false;
percentageLoaded = Application.GetStreamProgressForLevel(1) * 100;
guiText.text = percentageLoaded.ToString();
} else {
if (Application.GetStreamProgressForLevel(1) == 100)
percentageLoaded = Application.GetStreamProgressForLevel(1) * 100;
Debug.Log("Game started without pressing play");
}
Uhmm... why do you still have the GUI button around all this? That would mean all that code is only executed once when you pressed the button...
Also a GUI.Button only works inside the OnGUI function...
Your code is now a total chaos and doesn't make any sense. Your indention is also wrong, maybe you want to check your brackets and logic...
I will edit my answer to show this code snippet in a full script.
Yeah its a mess first time trying to get things to work with strea$$anonymous$$g webplayer
var $$anonymous$$enu$$anonymous$$usic : AudioClip;
var buttonColor : Color = Color.red;
var BackgroundColor : Color = Color.green;
private var about : boolean = false;
private var chooseQuality : boolean = false;
function Start(){
//Set Time Scale
Time.timeScale = 1.0;
//Find Cam
transform.position = camera.main.transform.position;
//Add Audio and Play It
gameObject.AddComponent(AudioSource);
audio.volume = .5;
audio.clip = $$anonymous$$enu$$anonymous$$usic;
audio.Play();
audio.loop = true;
//----------------------------------
}
function Update (){
//Unlock $$anonymous$$ouse
Screen.lockCursor = false;
}
function OnGUI (){
//Gui Color
GUI.contentColor = buttonColor;
GUI.backgroundColor = BackgroundColor;
//Buttons
if(GUI.Button (Rect ((Screen.width/2)-350,(Screen.height/2)-100,80,20), "Play"))
{
if (Application.GetStreamProgressForLevel(1) == 1)
GetComponent(GUITexture).enabled = true;
GetComponent($$anonymous$$ain$$anonymous$$enu).enabled = false;
percentageLoaded = Application.GetStreamProgressForLevel(1) * 100;
guiText.text = percentageLoaded.ToString();
}else{
if (Application.GetStreamProgressForLevel(1) == 100)
percentageLoaded = Application.GetStreamProgressForLevel(1) * 100;
Debug.Log("Game started without pressing play");
}
if(GUI.Button (Rect ((Screen.width/2)-350,(Screen.height/2)-50,80,20), "Options")) {
//
QualityOn();
}
if(GUI.Button (Rect ((Screen.width/2)-350,(Screen.height/2),80,20), "Controls")){
AboutOn();
}
if(GUI.Button (Rect ((Screen.width/2)-350,(Screen.height/2) + 100,80,20), "Quit")){
//Quit
Application.Quit();
}
//Others
if(about){
GUI.color = Color.white;
GUI.Label(Rect ((Screen.width/2) - 250,(Screen.height/2) - 100,500,500), GUIContent("$$anonymous$$OVE: W-A-S-D \n\n" +"RUN: Shift \n\n" + "JU$$anonymous$$P: Space \n\n"+"CROUCH: Ctrl \n\n"+"Shot: $$anonymous$$ouse1 \n\n"
+ "AI$$anonymous$$: $$anonymous$$ouse2 \n\n" + "SWITCH WEAPONS: $$anonymous$$ouse Wheel \n\n" + "FIRE $$anonymous$$ODE: Q \n\n" + "USE: E \n\n" + "LIGHT: F \n\n"));
//Do not remove this
//GUI.Label(Rect ((Screen.width/2) - 250,(Screen.height/2) + 250,500,500);
}
if(chooseQuality){
about = false;
//Give a Label
GUI.Label(Rect ((Screen.width/2)-200,(Screen.height/2) - 100,100,40), "Quality Settings");
if(GUI.Button (Rect ((Screen.width/2)-20,(Screen.height/2)-50,80,20), "High")){
QualitySettings.currentLevel = QualityLevel.Fantastic;
chooseQuality = false;
}
if(GUI.Button (Rect ((Screen.width/2)-120,(Screen.height/2)-50,80,20), "$$anonymous$$edium")){
QualitySettings.currentLevel = QualityLevel.Good;
chooseQuality = false;
}
if(GUI.Button (Rect ((Screen.width/2)-220,(Screen.height/2)-50,80,20), "Low")){
QualitySettings.currentLevel = QualityLevel.Fastest;
chooseQuality = false;
}
}
}
function AboutOn (){
about = true;
chooseQuality = false;
yield WaitForSeconds(10);
about = false;
}
function QualityOn (){
chooseQuality = true;
about = false;
}
Basically how i have this set out, there are currently 3 scenes, Scene 0 = is splash screen transaction Scene 1 = $$anonymous$$ain menu Scene 2 = Game
The thing im having trouble with is the fact its s$$anonymous$$$$anonymous$$g, So by the time the main menu has loaded the "Start" button wont load the game as its not fully streamed to 100% yet so im stuck looking at the main menu, So i want it to show a loading screen after i press the play button, once its at 100% the game scene loads in.