-5
\$\begingroup\$

I have created 3 scenes (StartMenu, Game, Win) and added all of them to built setting with proper arrangement. StartMenu Scene has a button start which should take game to second Game Scene when onClick event is called on it.

The onClick event of start button is mapped to LevelManager Empty Object. That object has a script LevelManager whose code I have posted.

I have added all those scenes to built settings.

but still I am getting this error:

Level 'name'(-1) couldn't be loaded because it has been added to the built settings.
To add a level to the built settings use menu File->Built settings.
UnityEngine.Application:LoadLevel(String)
LevelManager:LoadLevel(String) (at Assets/Scripts/LevelManager.cs:8) // 8 line is Application.LoadLevel line)
UnityEngine.EventSystems.EventSystem:Update()

LevelManager.cs

using UnityEngine;
using System.Collections;

public class LevelManager : MonoBehaviour {

    public void LoadLevel(string name){
            Application.LoadLevel(name);
    }

    public void QuitRequest(){
            Debug.Log("Quit Requested"); 
    }

}

Error Code snapshot(couldn't copy):

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I suggest you copy/paste the error message instead of trying to retype it. You've changed the meaning of the message with mistakes. \$\endgroup\$ – MichaelHouse Jul 21 '15 at 14:41
  • \$\begingroup\$ @Byte56 i couldn't copy it...so have uploaded the screenshot. Please have a look at it. \$\endgroup\$ – abhimanyuaryan Jul 21 '15 at 15:02
  • 1
    \$\begingroup\$ What is the exact string you are passing to LoadLevel? Debug it. \$\endgroup\$ – Adrian Krupa Jul 21 '15 at 15:08
  • \$\begingroup\$ -1. You should at least try to debug your code before asking the question. \$\endgroup\$ – S. Tarık Çetin Jul 29 '16 at 18:44
4
\$\begingroup\$

Error message tells you exactly what is wrong. You are trying to load scene with name name. You have to change the string in the editor in OnClick handler to Game in your case.

\$\endgroup\$
2
  • \$\begingroup\$ yaa you are 100% correct. But, I don't it clearly in error message. Which line that's it? \$\endgroup\$ – abhimanyuaryan Jul 21 '15 at 15:29
  • 2
    \$\begingroup\$ First line, second word. It's not variable name but variable value. Change text to dumb and you will notice the difference in error message. \$\endgroup\$ – Adrian Krupa Jul 21 '15 at 15:37
0
\$\begingroup\$

I was having the same issue. It worked one day, and not the next. I found that for some reason, it lost the link in the picture I provided. It worked fine after I updated all of the buttons on all of the scenes.

Screenshot

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.