x


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.

more ▼

asked Jan 11 '11 at 08:29 PM

Colin Allen gravatar image

Colin Allen
96 7 7 8

this script not work

May 24 '11 at 09:01 AM makram

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

May 01 '12 at 04:09 AM pitso 7

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

May 01 '12 at 04:11 AM Bunny83
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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;
    }
}
more ▼

answered Jan 11 '11 at 10:10 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

i dont think it worked. mabey its because i dont have much to load. idk. thanks anyways :D

Jan 12 '11 at 04:27 PM Colin Allen

Does it give an error message? Did you set a texture to use?

Jan 12 '11 at 04:39 PM Statement ♦♦

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.

Mar 03 '11 at 03:51 PM Matt Carver

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.

Dec 07 '12 at 03:00 AM MachCUBED

Statement, how to use your script? It doesn't show an image when loading

Jan 23 at 10:00 AM Websfera.pl
(comments are locked)
10|3000 characters needed characters left

I just put a post up about this at Fervent Interactive Blog

more ▼

answered Feb 06 '12 at 07:49 PM

Fervent gravatar image

Fervent
175 1 1 8

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

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;
}
more ▼

answered Jun 11 '11 at 06:02 PM

Dreamer gravatar image

Dreamer
1.5k 39 49 66

Would you attach this to the main camera?

Apr 16 '12 at 06:21 PM TheFrankman123

also i'm getting unknown identifier GameData

Apr 16 '12 at 06:31 PM TheFrankman123

How would this work you never set loading_on to true. Wouldn't you need
If(Application.isLoadingLevel){ loading_on = true; }

Aug 18 '12 at 06:13 PM landon91235

You may attach this to any camera, I have mine 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!

Dec 19 '12 at 04:31 PM st362
(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:

x717
x322
x297
x106

asked: Jan 11 '11 at 08:29 PM

Seen: 13599 times

Last Updated: Jan 23 at 10:15 AM