Application Load Level Issue

For the life of me I can’t get Application.LoadLevel(int or string) to load the next level when a button is pushed.

int lvlLoad = 1; // holds the integer value of the level to load (0 = login, 1 = char create, 2 = char select, etc)
					Debug.Log("Loading Level: " + lvlLoad);
					Application.LoadLevel(lvlLoad);

after which the following is returned:

Loading Level: 1

But… alas, nothing loads :frowning:

PS - the index’s are taken from Build Settings also.

Is there a level 1? Those numbers mean nothing until the build configuration is done and they have been indexed. You can also load a level by name with a string.

Yes of course.

Edit: Just tried this method as well:

					if (lvlLoad == 0)
						Application.LoadLevel("LoginScreen"); 
					else if (lvlLoad == 1)
						Application.LoadLevel("CharacterCreation");
					else if (lvlLoad == 2)
						Application.LoadLevel("CharacterSelection");

as well as just: Application.LoadLevel(“LevelStringName”);

There could be several reasons for this to happen. I assume you added the scene to the build settings? Does the scene have anything in it?

Do you get any console errors at all?

No console errors.

They are in the build settings.

All 3 scenes have something in them, and I can play each scene individually and it works just fine, but the LoadLevel, with string or int - NEVER load :frowning:

I made a test project and I had no trouble switching levels with a button. Do you get the same problem in another project?

No.

Would it have anything to do with me using MySQL? I doubt it should, just curious.

Make sure you build your game up with all levels included in the build, this code works for me:

using UnityEngine;
using System.Collections;

public class LevelMaster : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter(Collider other)
	{
		Debug.Log(other.gameObject.tag + "  " + Application.loadedLevelName);
		switch(Application.loadedLevelName)
		{
			case "Scene1":
			Application.LoadLevel("Scene2");
			break;
			case "Scene2":
			Application.LoadLevel("Scene1");
			break;
		}
	}
}

However, my levels are called Scene1 and Scene2, replace that with the name of your levels, I used cubes as my level switch triggers.

Ok so I commented out all the coding in my button, and just used Application.LoadLevel("Level2"); // Level2 is just an example

and that works fine… quite strange. Are there any certain functions, or bugs I should be worried about if I’m using MySQL?

EDIT:

Solved! In my “MySQL” C# script I was using a public void Close(), changed it to sqlClose() and now it works!

Thanks.

In my current project I am communicating with MySQL by sending a WWWForm to a PHP script. After submitting the form I have no trouble loading levels.

How do you communicate with MySQL? Nothing as far as I know should stop a level from loading unless it causes the program to freeze, or maybe it is waiting/yielding for something?

I actually am using Connecter.NET (well something similar, no PHP files are needed, if you want to take a look PM me some way to get a hold of you, preferably AIM/MSN/etc)

if you do direct connects to DBs just keep in mind that you expose your whole db to any enduser cause the webplayer / standalone runs on their system not your website thus it needs wildcard accounts …