[SOLVED] I'm getting an error on "LevelManager.LoadLevel(name);"

I don’t remember changing anything but as I started editing the LevelManager script whilst watching this lecture, I started getting an error popping up next to “LevelManager.LoadLevel(name);” on Line 10 of my script, I’m not really sure what’s going on. This is currently halting my progress as I cannot build the code without fixing the error so I’m grateful for any advice asap.
I will attach an image of my script because I expect I’m overlooking something obvious but please do ask if you would like a copy of the file.
Thanks in advance.

You are calling LevelManager.LoadLevel from inside its own definition. What you need to call is Application.LoadLevel(name);

1 Like

Thanks! I knew it was gonna be small and stupid of me haha :slight_smile:

Actually I just saw that you are using the SceneManagement namespace, so I guess you are using unity 5?
In that case, you should probably use SceneManager.LoadScene(name), but if the first option works it’s fine too :wink:

1 Like

Correct, I’m using Unity 5. I’m up to the point where Ben is teaching us how to use the index’s to navigate between levels, but honestly, I might just keep the ‘levelmanager.loadlevel’ stuff. I prefer it since it helps me know whats going on a little better.

Oh, my bad. I see what you mean now, it would actually be so much easier for me to just use “scenemanager.loadscene(name)”. Thanks for informing me of that too!

1 Like

No problem, it functionally does the same thing anyway, it’s just the more recent version :slight_smile:
The use of index instead of name can be useful though, especially when your games start having a lot of levels (you probably don’t want to input each individual level name manually).
Anyway, glad I helped :wink:

1 Like