Load Level help...

I have currently two levels ready to build. I have the loevels loaded into Build Settings panel. I understand the Loadlevel script, but I don’t know what to attach it to to have it function. Also, what is the syntax that I can add to the script to add time to the loadLevel script? I would like my splash screen to stay up for 3 seconds.

Thank you for your time,

Gary

Aha-I think I can help here…

http://forum.unity3d.com/viewtopic.php?t=2316&highlight=

http://forum.unity3d.com/viewtopic.php?t=2518&highlight=

var myGui : GameObject; 
function Start (){
myGui.active = false;
}
function OnCollisionEnter()
{
myGui.active = true;
    Application.LoadLevel("Level2final");
}

this obviously uses a collision with a mesh(turn its renderer off)

HTH
AC

I’m sorry for being so ignorant… Where do I put/attach the LoadLevel script? I do not need a collision. Just a splash/credits screen and enough time to read it and then load the simulation immediately following that. Thanks again everyone.

Cheers,

Gary

Somethings gotta trigger it, even if its just a timer…

function Start() 
{ 
yield WaitForSeconds(60);
    Application.LoadLevel("Level2final"); 
}

You generally make an empty Game Object in the scene.
These are often refered to as “managers”.

EG I often have an audio manager, a script manager, and a gui manager. I make in game gui’s children of the gui manager, etc.

Create an empty GO and drag your script onto there. It just needs to be in the scene (anywhere).

Heres a handy gui script I made:

var myGui: GameObject;
var Guioff= 45.0; 
var OnTime= 45.0; 
function Start () { 
    myGui.active = false; 
    yield WaitForSeconds(Guioff);
    myGui.active = true; 
     yield WaitForSeconds(OnTime);
    myGui.active = false; 
   
}

So tell me, what is going to load the level? A timer, a collision?, another set of behaviours?
AC

A timer would be what I would like. Or even better a keystroke. Something akin to ‘press spacebar to start’ as gui text over the credits screen. Thanks Targos!

Cheers,

Gary

var myGui: GameObject; 


function Start () { 
myGui.active = false; 

if (Input.GetButtonDown ("Jump"));
    myGui.active = true; 
    Application.LoadLevel("GarysLevel2OrWhatever"); 
}

thats the spacebar one
The timer is the smaller snippet with the yield statement.Enjoy!
AC

Targos,

Thanks. I have created an empty GameObject and attached your script. I changed the code like below. I wasn’t sure what the “GarysLevel2OrWhatever”(is this the scene name? i.e. MyTest1.unity) code would have been referring to… Could I use the value of 1 like below. It doesn’t give an error but it doesn’t work either.

var myGui: GameObject;

function Start () {
myGui.active = false;

if (Input.GetButtonDown (“Jump”));
myGui.active = true;
Application.LoadLevel(1);
}

change Start to Update. Right now you are only checking if the key was pressed on the first first frame. While what you want is to check every frame.

Thanks. I apologize it still doesn’t work. No error in the console. Here is what I have. In the Build Game panel I have my assets checked and listed as follows:

assets/splashscreenlevel.unity 0
Assets/MyTest1.unity 1

I updated the code as you suggested. When I execute the Build and start the application, the spacebar does not load the level 1 object and have the Gui splash screen disappear. Thanks for any further help.

Cheers,

Gary

To which game object did you attach the script?
Is the game object in the first level?

Btw. you can also preview level loading in the editor. Just open the first scene you dragged in the build player dialog as the first level. Then hit play.

Thanks Joachim! It wasn’t in Level 0!!! Wow easy to fix that one!!! Thanks to both of you I now understand the Level stuff and some more code!

However it just goes from the splash screen to the Level 1 on its own after a second or so… hmmmm?

Cheers,

Gary

i’m not sure but it sounds like you’re not waiting for input. example from my script:

function Start ()
{
	DontDestroyOnLoad (this);
	
	while (!Input.GetButtonDown("StartArena"))
		yield;
	
	Loading();
}

function Loading ()
{
	notes.SendMessage ("FadeOut", 1.5);
	transportTX.SendMessage ("FadeOut", 1.5);
	yield WaitForSeconds (1.5);
	mainCam.GetComponent(GUILayer).enabled = false;
	LevelLoadFade.FadeAndLoadLevel("LV01", Color.black, 1.0);
	yield WaitForSeconds (2.0);
	transportFX.emit = false;
}

the important part is:

while (!Input.GetButtonDown(“StartArena”))

I don’t need a fade out on this, it could work but I do not understand the code for (this) and for (!Input.GetButtonDown(“StartArena”)). Fadeout is very cool though.

I just timed the splash screen to loading Level 1 and it is roughly 4 seconds. This is ok but I don’t understand why the spacebar function isn’t working…

Would I replace my code with yours or append it to it in some fashion?

Cheers,

Gary

oh ok, sorry - that’s just what i was using which was modified from the FPS tut.

DontDestroyOnLoad (this); is just saying “don’t kill the object this script is attached to when loading a new level”

the !Input line is just saying while (whatever your chosen button is) is not pressed, don’t do anything, if i understand it correctly. its just another way to do it i guess. putting your above code in an update function should work as well like joachim said. the code i posted has other stuff in it not applicable(the loading function) i just showed that for example.

i think maybe your best bet is to post the script your working with. (is what you posted above it?)

This is it here.

var myGui: GameObject; 


function Update () { 
myGui.active = false; 

if (Input.GetButtonDown ("Jump")); 
myGui.active = true; 
Application.LoadLevel(1); 
}

active = false should be in start as below (you don’t need to set that every frame). this should work, i’m not really a good coder i think someone else might have to help you. the only other thing i can think of is your jump button is not mapped correctly or there was something changed in the load level script.

i’ll make one last attempt, for a test try and replace your script with this:

var myGui : GameObject;

function Start ()
{
	myGui.active = false;
	while (!Input.anyKeyDown)
		yield;
	
	Loading();
}

function Loading ()
{
	myGui.active = true;
	Application.LoadLevel(1);
}

does this work? (it should load only when you press a key)

When Using the first script I get the following error:

Assets/Standard Assets/Scripts/Lifestyleloader2.js(12) error BCE0044: expecting :, found '=".

When using the second script nothing happened… :frowning:

What do I set the My Gui selector to in the Inspector window? the scene for level 0, the empty GameObject?

Thanks.

Gary

I have attached a screengrab of my first Level. Maybe this could help???

try commenting out all the myGui stuff from your script and see if it works. it looks to me like myGui is referencing itself, which i think is wrong, i.e you’re turning the scipt off at start (i think ; )

//var myGui : GameObject; 

function Start () 
{ 
   //myGui.active = false; 
   while (!Input.anyKeyDown) 
      yield; 
    
   Loading(); 
} 

function Loading () 
{ 
   //myGui.active = true; 
   Application.LoadLevel(1); 
}

EDIT AGAIN: oh i think i see, is the gameobject with the load script your GUI object as well? if so move the load script to a different empty gameobject name it “loader” or something, and click on it, then drag your gui gameobject into the script variable.