- Home /
Loading Screen?
Hi,
I have a qeustion,
I want to make a loading screen, somthing that says "Loading". but i dont want to have to make a new scene per level. basicly, if a level is loading, can i make it spawn a GUI everytime its loading somthing.
i know this is very hard to explain but i need a little help.
hello so i am new to unity and i do not understand where to put the loading scene script can anybody help me i know I'm asking this and its a stupid question but nobody really explained where to put it
@pitso: This is not an answer to the question! Use comments is you have a short question about a specific post. If you have a real question, post a question-
O$$anonymous$$, might I suggest a basic idea (maybe someone who gets what I'm saying put it in code form, because at this moment I don't have time to do that :P): basically, you use a CUSTO$$anonymous$$ function named "CustLoadLevel" in a level loader script, with one string argument "levelToLoadCust". Then have all objects that could possibly need to send a message to load the level to have a reference to an object with CustLoadLevel so they can use ".Send$$anonymous$$essage". Then, have the level loader script read in the level and before loading the level, overlay a GUI item with the loading texture, so while the next level is loading the screen is displaying the loading screen while remaining in the same level. I dont know I'll refine this later, I guess.
this is Brilliant... I was going to use a scene for my loading but this is easier and all I really want is a meteor spinning so this should work for that?
void Update() { if(!Application.isLoadingLevel) hide(); }
public static void loadLevel(string sceneName) { LoadingScreen.show(); Application.LoadLevel(sceneName); }
Answer by Statement · Jan 11, 2011 at 10:10 PM
Sure, here is a script I created.
It acts like a singleton, and you can easily set it up in your first scene. Just give it a texture and you are all set. You can use it like LoadingScreen.Load(levelIndex); and it will show the texture on screen.
using UnityEngine;
public class LoadingScreen : MonoBehaviour { public Texture2D texture; static LoadingScreen instance;
void Awake()
{
if (instance)
{
Destroy(gameObject);
return;
}
instance = this;
gameObject.AddComponent<GUITexture>().enabled = false;
guiTexture.texture = texture;
transform.position = new Vector3(0.5f, 0.5f, 0.0f);
DontDestroyOnLoad(this);
}
public static void Load(int index)
{
if (NoInstance()) return;
instance.guiTexture.enabled = true;
Application.LoadLevel(index);
instance.guiTexture.enabled = false;
}
public static void Load(string name)
{
if (NoInstance()) return;
instance.guiTexture.enabled = true;
Application.LoadLevel(name);
instance.guiTexture.enabled = false;
}
static bool NoInstance()
{
if (!instance)
Debug.LogError("Loading Screen is not existing in scene.");
return instance;
}
}
i dont think it worked. mabey its because i dont have much to load. idk. thanks anyways :D
Does it give an error message? Did you set a texture to use?
I'm looking for something similar and I came across this script and I've been trying to get it to work.
I could be wrong about this, but shouldn't the NoInstance() function be called as:
if(!NoInstance()) return;
Otherwise when the instance does exist, NoInstance() will true and the Load function will exit without actually loading the scene.
I tried it, and while it's loading my stuff just fine with no error messages, it's stil not showing the image that I set as my loading image. The script is attached to a GameObject with the same transform as the camera in my initial scene, and the transform of the GameObject has no effect on what shows up. FTR, I'm using this in conjunction with NGUI.
Statement, how to use your script? It doesn't show an image when loading
Answer by Dreamer · Jun 11, 2011 at 06:02 PM
I found out to do loading screen is so easy after I implemented myself. Here is to share with everyone:
static var loading_on : boolean;
var Loading_Screen:Texture2D;
function OnGUI () {
if(loading_on){
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(1.0*Screen.width/GameData.X, 1.0*Screen.height/GameData.Y, 1.0));
GUI.depth =-10;
GUI.Box(new Rect(0,0,1024,768),Loading_Screen);
}
if(!Application.isLoadingLevel)
loading_on=false;
}
How would this work you never set loading_on to true. Wouldn't you need
If(Application.isLoadingLevel){ loading_on = true; }
You may attach this to any camera, I have $$anonymous$$e attached to an object. When someone clicks on the object, I turn loading_on=true; Then my loading screen is activated. The GameData is just a placeholder, you must adjust the GUI.matrix to whatever size you want. GUI.matrix translates, scales, and rotates your loading screen. This loading screen is working really good if you want something simple, thanks for sharing!
The loading_on variable is redundant, just the Application.isLoadingLevel is enough, though. :P
def OnGUI ():
if Application.isLoadingLevel:
GUI.Box(Rect(0,0,Screen.width,Screen.height),Loading_Screen)
GUI.Label(Rect(Screen.width/2-10 , Screen.height*3/4, 200, 100),loading.ToString()+" %")
loading+=Random.Range(10,30)
Answer by lliviu · Sep 07, 2013 at 06:29 PM
Statement's code didn't work for me. Here is the modified version:
using UnityEngine;
using System.Collections;
public class LoadingScreen : MonoBehaviour
{
public Texture2D texture;
static LoadingScreen instance;
void Awake()
{
if (instance)
{
Destroy(gameObject);
hide();
return;
}
instance = this;
gameObject.AddComponent<GUITexture>().enabled = false;
guiTexture.texture = texture;
transform.position = new Vector3(0.5f, 0.5f, 1f);
DontDestroyOnLoad(this);
}
public static void show()
{
if (!InstanceExists())
{
return;
}
instance.guiTexture.enabled = true;
}
public static void hide()
{
if (!InstanceExists())
{
return;
}
instance.guiTexture.enabled = false;
}
static bool InstanceExists()
{
if (!instance)
{
return false;
}
return true;
}
}
I call i from my GameController class like this:
public static void loadLevel(string sceneName)
{
LoadingScreen.show();
Application.LoadLevel(sceneName);
}
Don't forget to put it on an empty object and set the texture.
Tried this but LoadingScreen still exists after new scene loads!
Does that mean that the LoadingScreen object exists even though a new scene loads?
I found a solution, take his exact code but add this to the LoadingScreen class:
void Update()
{
if(!Application.isLoadingLevel)
hide();
}
What its doing is that it checks if the application is loading a level. If not, then hide the splash screen.
Answer by Fervent · Feb 06, 2012 at 07:49 PM
I just put a post up about this at Fervent Interactive Blog
Answer by Bonkurazu · May 15, 2015 at 08:27 AM
How about something like this
//meant to be placed on a GameObject other ones can have a reference to so activation with .SendMessage is possible
//UNTESTED
using UnityEngine;
using System.Collections;
public class CustomAsyncLoader : MonoBehaviour
{
//objects / stuff to show
void Start(){} //forgot if this is required for a MonoBehaviour
void Update(){} //ditto
void customLoadLevelAsync(String level) //call to load level
{
//show graphics somehow, possibly via rendering with a camera with a higher depth than all other ones
AsyncOperation asyncOp = Application.loadLevelAsync(level);
yield return asyncOp;
Debug.log("Load to " + level + " success.");
}
}
void start and void update isn't required for a $$anonymous$$onoBehaviour