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 Romejanic · Mar 05, 2015 at 10:59 AM · guibugscenesloading screen

Loading screen only works once

I have made a loading screen for my game. On here, it will show the progress of loading (I have a big scene) and it will display tips for the game. The loading screen works, but it only loads one scene before breaking completely. I am handling scene loading with the script, I call LoadingScreen.loadScene("scene_name") to load the scene only if I want to use the loading screen. That then sets a static string and loads the loading scene, which creates an AsyncOperation with the static string, and you know the rest. But again, this process only works once, and after that the AsyncOperation is instantiated by LoadLevelAsync, but doesn't actually do anything. I've even set up hooks to detect if the scene isn't loading anything, and there's still problems.

Here's the script: using UnityEngine; using System.Collections;

 public class LoadingScreen : MonoBehaviour {
 
     private static string sceneToLoad;
     private static AsyncOperation async;
 
     public string[] tipTexts = { "This is a test message!" };
     private string tipText;
     private float timeToChange = 10f;
     private GUIStyle style = new GUIStyle();
 
     public Font font;
 
     void Start () {
     
         GenerateNewText();
 
         style.font = font;
         style.normal.textColor = Color.white;
         style.fontSize = 25;
 
         if(sceneToLoad != null && async == null) {
 
             async = Application.LoadLevelAsync(sceneToLoad);
 
         }
 
     }
 
     void GenerateNewText() {
 
         string txt = tipTexts[Random.Range(0, tipTexts.Length)];
 
         if(txt == tipText) {
 
             return;
 
         }
 
         tipText = txt;
 
     }
 
     void Update() {
 
         timeToChange -= Time.deltaTime;
 
         if(timeToChange <= 0f) {
 
             GenerateNewText();
             timeToChange = 10f;
 
         }
 
     }
 
     void OnGUI() {
 
         style.alignment = TextAnchor.MiddleCenter;
         GUI.TextArea(new Rect(0, 0, Screen.width, Screen.height), "Loading\n\n\n" + tipText.Replace("\\n", "\n") + (async == null ? "\n\nNot Loading" : ""), style);
         style.alignment = TextAnchor.LowerLeft;
 
         GUI.Label(new Rect(10 + ((Screen.width - 10) * getLoadProgressF()), 0, Screen.width - 10, Screen.height - 10), getLoadProgress().ToString() + "%", style);
 
     }
 
     public int getLoadProgress() {
 
         return (int)(getLoadProgressF() * 100f);
 
     }
 
     public float getLoadProgressF() {
 
         if(async == null) {
 
             return Input.mousePosition.x / Screen.width;
 
         }
 
         return async.progress;
 
     }
 
     public static void loadScene(string scene) {
 
         sceneToLoad = scene;
         Application.LoadLevel("load_scene");
 
     }
 
 }
 

The scene is just am orthographic camera with this script attached, so it loads quickly and because all of the loading screen is GUI-based.

Does anyone know what's going on? Fixing this problem is important, because I need to use this loading screen a lot in the final game. Thanks, Romejanic

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

Answer by Romejanic · Mar 05, 2015 at 11:32 PM

My god I'm an idiot. I know what's happening. The async operation is static and is not being redefined -_-

Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

GUI.Style is messing up big time 0 Answers

switching scene, first one stops to work properly 1 Answer

GUI Skin Layout Issues 0 Answers

GUI Bug in compiled game. 0 Answers

Fade out effect isn't working if loaded at the second time. 2 Answers


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