Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheTurkeydipking · Feb 22, 2013 at 09:55 PM · c#guibuttonloading

Help with C# coding a loaded button (3.x Game Development Essentials)

Hey everyone! I've been following Will's excellent new book "3.x Game Development Essentials" and fished it earlier today, however there is a small hiccup causing me some annoyances... In the book he creates a Play button, but if the game is to be loaded in a web player, this play button is replaced by a "loading" button, until 100% has been loaded, and then the button should swap back over to play. My problem lies with 2 things; 1. This button also appears on the Standalone version 1. The button is always there. Above my play button, the "Loading..100% loaded" is always visible (this doesnt prevent you from clicking the play button though) I checked over the book plenty of times, but simply cannot figure out where I went wrong, I'm pasting my entire "MenuButtons" script below, hoping for some help (:

using UnityEngine; using System.Collections; [RequireComponent (typeof (AudioSource))]

public class MainMenuGUI : MonoBehaviour {

public AudioClip beep; public GUISkin menuSkin; public Rect menuArea; public Rect playButton; public Rect instructionsButton; public Rect quitButton; Rect menuAreaNormalized; string menuPage = "main"; public Rect instructions;

 void Start() {
 menuAreaNormalized = new Rect(menuArea.x * Screen.width - (menuArea.width * 0.5f), menuArea.y * Screen.height - (menuArea.height * 0.5f), menuArea.width, menuArea.height);
     
     }
 
 void OnGUI() {
     
     GUI.skin = menuSkin;
     GUI.BeginGroup (menuAreaNormalized);
     
     
 if(menuPage == "main") {
             
         if(Application.CanStreamedLevelBeLoaded("Island")){
             if(GUI.Button(new Rect (playButton), "Play")) {
                 
                 StartCoroutine("ButtonAction", "Island");
             }else{
             
                 float percentLoaded = 
                 Application.GetStreamProgressForLevel(1) * 100;
             GUI.Box (new Rect(playButton), "Loading.." + percentLoaded.ToString("f0") + "% Loaded");
         }
     }
         
             if(GUI.Button(new Rect (instructionsButton), "Instructions")) {
                 audio.PlayOneShot(beep);
                 menuPage="instructions";    
         }
         
         if(Application.platform != RuntimePlatform.OSXWebPlayer && Application.platform != RuntimePlatform.WindowsWebPlayer){
         if(GUI.Button(new Rect (quitButton), "Quit")) {
                 StartCoroutine("ButtonAction", "quit");    
             }
             
         }
     } else if(menuPage == "instructions") {
         GUI.Label (new Rect(instructions), "You awake on a mysterious island... Find a way to signal for help or face certain doom!");
         if(GUI.Button (new Rect(quitButton), "Back")) {
             audio.PlayOneShot(beep);
             menuPage="main";
         }
     }
     
 
 GUI.EndGroup();
 }
 

 
 IEnumerator ButtonAction(string levelName) {
     audio.PlayOneShot (beep);
     yield return new WaitForSeconds(0.35f);
     
     if(levelName != "quit") {
         Application.LoadLevel (levelName);
     }else{
         Application.Quit ();
         Debug.Log ("HaveQuit");
     }
 }
 
 }



The specific snippet affecting the button is here;

if(Application.CanStreamedLevelBeLoaded("Island")){ if(GUI.Button(new Rect (playButton), "Play")) {

             StartCoroutine("ButtonAction", "Island");
         }else{

             float percentLoaded = 
             Application.GetStreamProgressForLevel(1) * 100;
         GUI.Box (new Rect(playButton), "Loading.." + percentLoaded.ToString("f0") + "% Loaded");
     }
 }


Thank you so much in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by prototype7 · Feb 23, 2013 at 01:20 AM

what if you add this script

 GUI.BeginGroup (menuAreaNormalized);
 
 if (Application.platform == RuntimePlatform.OSXWebPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer)
     {    
          // GUI stuff
     }
 
 GUI.EndGroup();
 
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheTurkeydipking · Feb 23, 2013 at 12:15 PM 0
Share

And it works! :) Thank you so much mr./ms. prototype! :)

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Preserving a scene while loading anather scene using ui button 1 Answer

Making a button desplay after pressing a button? 2 Answers

C# Why Won't My GUI Layout Button Appear? 1 Answer

How to instantiate a prefab between Canvas and a Button? 0 Answers

hide button 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges