x


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();

      }  
   }
more ▼

asked May 16 '12 at 10:55 PM

British89 gravatar image

British89
36 3 5 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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...

more ▼

answered May 16 '12 at 11:16 PM

Bunny83 gravatar image

Bunny83
45k 11 48 206

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(MainMenu).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");

      }
May 16 '12 at 11:48 PM British89

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.

May 17 '12 at 01:37 AM Bunny83

Yeah its a mess first time trying to get things to work with streaming webplayer

var MenuMusic : 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 = MenuMusic;
   audio.Play();
   audio.loop = true;
   //----------------------------------
}
function Update (){
   //Unlock Mouse
   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(MainMenu).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("MOVE: W-A-S-D \n\n" +"RUN: Shift \n\n" + "JUMP: Space \n\n"+"CROUCH: Ctrl \n\n"+"Shot: Mouse1 \n\n"
      + "AIM: Mouse2 \n\n" + "SWITCH WEAPONS: Mouse Wheel \n\n" + "FIRE MODE: 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), "Medium")){
         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;
}
May 17 '12 at 01:58 AM British89

Basically how i have this set out, there are currently 3 scenes, Scene 0 = is splash screen transaction Scene 1 = Main menu Scene 2 = Game

The thing im having trouble with is the fact its steaming, 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.

May 17 '12 at 02:03 AM British89
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x810
x660
x39

asked: May 16 '12 at 10:55 PM

Seen: 459 times

Last Updated: May 17 '12 at 02:03 AM