What's the different between two of this sources?

hello, i have a question about this lecture

this source
levelManager.LoadLevel(“Win Screen”);
and this source
Application.LoadLevel (“Win Screen”);

what’s the different between this source ?
can i use them both ?

thank you for reading
have a nice day

I think you can use both them.
Because we made LevelManager.LoadLevel method from Application.LoadLevel method.

public class LevelManager : MonoBehaviour {

____public void LoadLevel ( string nameLevel ) {
________Application.LoadLevel (nameLevel);
____}

}

1 Like

That’s right, you could use either, however in the LevelManager class you may want to do other things also, before loading the next level.

If you wrap these methods up this way, should you need to change how the level is actually loaded in the future, you will only need to change it in the LevelManager, the rest of your code will still be calling LevelManager.LoadLevel.

On that note, when you move to Unity 5 you probably will want to change it, as Application.LoadLevel has been deprecated and replaced with SceneManager.LoadScene(), but don’t worry about that for now, it will give you a good example as to why to have the LevelManager sitting in between.

1 Like

Hey @Rob,

So if I understood that correctly we are creating a second Level Manager that serves the same purpose as our Level Manager Script however, the Level Manager within the Collider Script allows us to make certain adjustments in how to load or quit anything related to where the collider script is applied?

Hi @Bryan_FP,

Not quite, but close.

The original poster asked about the difference between Application.LoadLevel and our own LevelManager.LoadLevel methods.

LevelManager provides a method which in turn calls Application.LoadLevel, but, it means you can add additional code if you should so wish to the level loading method also, and all in one place.

For example, if we only used Application.LoadLevel, you would probably find it mentioned in numerous scripts across your game. What if - and shock horror it has actually happened - Unity decided to make the Application.LoadLevel method obsolete, we would then need to go through the entire application finding all references and changing them to whatever the alternatively is.

If we also had decided to pop up a panel on the screen to the user a few seconds before loading the next level to say “Level Complete” or something like that, we may have set the background colour, and image, font size or any number of other things, again, this may be duplicated all through our application.

By wrapping up common functionality in this manner and popping it into LevelManager, whilst we will still make a number of calls to our LevelManager within our application this is ok, as we will be able to change the inner workings of that as and when we want to, but importantly - just the once.

In the example above, I would edit LevelManager and swap out Application.LoadLevel for SceneManager.LoadScene for example. Or, if I also had wrapped other code up into this too, this is where I would change that - once. All of the calls throughout the application would still work nicely without change.

Does this answer your question? Let me know if not :slight_smile:

Privacy & Terms