x


OnTriggerEnter to load Level and display message help...

Hello guys,

I am using OnTriggerEnter to load next level as player enters an area, what i am having trouble with is displaying text on screen to alert player that next level is loading...Can you help??

function OnTriggerEnter (col : Collider) {
    print("Loading Next Level");
    yield WaitForSeconds (5);
    Application.LoadLevel (3);
}
more ▼

asked Oct 18 '11 at 07:51 PM

xmediagrafx gravatar image

xmediagrafx
69 8 8 16

shouldn't this at least display the text "Loading Next Level" on screen? Or is the WaitForSeconds delaying everything including the text? Countdown isn't as important, just need it to at least put text on screen to inform player that level is loading, but "print" or "guiText" not working....

Oct 18 '11 at 08:37 PM xmediagrafx

this won't display the text on screen but rahter in the console.Use a GUI text or something

Oct 19 '11 at 12:37 PM BogdanC
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You could just make a level load that's just a loading screen, with 3dText centered on the camera while the actual level loads. //At the top of the Screen: GameObject -> Create New -> 3dText(Gui Text might also work)

and then have THAT loading screen load your next level! Then you could throw in a cool splashscreen while the next level loads, although to be honest, if I ever had to load a unity level for more than a few seconds it's usually too choppy to even play

more ▼

answered Oct 18 '11 at 11:12 PM

Sun_Glasses_Guy gravatar image

Sun_Glasses_Guy
16 4 4 4

I was thinking this as well, but would still like to learn how to trigger GUI with OnTriggerEnter...

Thanks!

Oct 19 '11 at 12:41 AM xmediagrafx
(comments are locked)
10|3000 characters needed characters left

From Unity 3d forum - create a small game object, with a script attached, that sets DontDestroyOnLoad in its awake function. This game object displays your text for "please wait, loading..." and then after a few seconds, and definitely after the level has loaded, the game object destroys itself.

Code:

function OnTriggerEnter(col : Collider)
{
GameObject.Instantiate(yourLoadingGameObject, Vector3.zero, Quaternion.identity);
Application.LoadLevel(3);
}

Then stick this script on whatever object you want to instantiate just before you load your level. Code:

public class LoadingMessage : MonoBehaviour
{
    void OnLevelWasLoaded(int level)
    {
        Destroy(this.gameObject, 3.0f);
    }

    void Awake()
    {
        DontDestroyOnLoad(this.gameObject);
    }

    void OnGUI()
    {
        GUI.Label(new Rect(50, 50, 200, 25), "Loading next level...");
    }

}
more ▼

answered Oct 19 '11 at 12:33 PM

xmediagrafx gravatar image

xmediagrafx
69 8 8 16

(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:

x337
x313
x63
x54

asked: Oct 18 '11 at 07:51 PM

Seen: 1590 times

Last Updated: Oct 19 '11 at 12:37 PM