[SOLVED] Major Issue with LevelManager

Hey all, I am having a catastrophic error, can’t seem to fix it, and am at a complete loss of what to do.

Here is what I think my issue stemmed from:
After starting work on the project, I got to the lesson where we add the grass to the background, and I decided to import all the assets that are attached to the course for this section, and I imported all of them into the project.

What has happened:
My levelmanager script has been removed from all of my buttons throughout the game.

What have I tried:

  • reattaching the levelmanagerscript, but when I do so, the only function I can choose is Monodevelop -> string name which is not what I want. I am looking for the old LoadLevel bit.
  • Using a prefabbed level manger that I found in the prefabs folder. I don’t necessarily remember prefabbing this. I may have, but I wonder if it came from the package import I did.
    -borrowed the old levelmanager script from block defender because it should give me the functionality I need. Didn’t work, still just Monodevelop -> string name is available.
    -Copied a levelmanager script to a new script name on a new button

What should happen:
I should be able to drop the script into the button, and have it do the LoadLevel string execution.

Please help. Where have I gone wrong! Level manager script to follow:

using UnityEngine;
using System.Collections;

public class LevelManager : MonoBehaviour {

public void LoadLevel(string name){
	Debug.Log ("New Level load: " + name);
	Application.LoadLevel (name);
}

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

public void LoadNextLevel() {
	Application.LoadLevel(Application.loadedLevel + 1);
}

}

Hello Tyler, how are you?

Are you trying to drag the script from your assets straight to the button inspector? If so, then I think that it won’t work. You should add a script that has been instantiated inside the scene to the button inspector, or even the gameObject that contains the LevelManager script.

I’m not in my Unity computer to confirm this, but I’ve come across this kind of problem a couple of times and this solution was enough for me.

Thanks for the reply. I will give that a shot as soon as I am home from work!

1 Like

It didn’t work. I made a new button, and then put the new script on there, and still have the same issue. I made a copy of my Glitch Garden folder, and zipped it up if anyone would be interesting in me sending it to them to see if they have the same issue or if physically seeing what I am will help come up with a solution.

I am at my wits end here! I guess I will go back into Laser Defender and spice mine up until I can think of an answer.

Alright folks, @ben would be super proud of me, because I spent hours digging through the docs and online forums and seem to have found my solution.

A lot of people have this problem it seems, and what caused it was my mass import of assets midway through the project. The solution most people use then is to move the script out of the games directory, refresh the assets, and move it back. Well, I hadn’t done that. I tried to create a script with a different name, and just copy and pasted the old script, into this new script with a different name. This caused the engine to freak out.

All I had to do was go and make sure that the class name in the script, matched the name of the file, then refresh the assets, and voila! It worked!

We’re back in business baby!

3 Likes

Unity is very particular about that - well done on finding your resolution :slight_smile:

Privacy & Terms