Issue with Start button on start screen - Unity 5.6.1f1

For some reason, my Start button on the opening start scene won’t work.
It keeps saying this:

I haven’t done anything really special with the LevelManager script… I made it the function Static, but I’ve tried it both ways, and nogo.
Here’s my code:

using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;

public class LevelManager : MonoBehaviour

public static void LoadScene(string name)
	Debug.Log ("LoadScene called for " + name);
	SceneManager.LoadScene (name);

public void QuitGame(){
	Debug.Log ("QuitGame requested");
	SceneManager.LoadScene ("Quit");


remove static.

I don’t fully understand static yet but I know it’s the problem here :smiley:

I did… didn’t change it. I think I stated that I tried with and w/out

The only way I can reproduce your problem is by adding ‘static’ or removing the method …

Sorry I can’t help more than that :confused:

Are you dragging the script directly into the OnClick() event on the Start bytton?

If so, you need to create a GameObject in the Hierarchy first (name it LevelManager), attach the LevelManager script to that, then drag the LevelManager game object from the hierarchy into the OnClick() event.

After you have done this you should be able to select your public method LoadScene() and enter the level name as the parameter text.

Remove the static declaration also.

I’ve done all that… I’ll try it again when I get home. I’ll also kill the
script and make a new one, just in case.

Shouldn’t be any need to recreate the script, assuming it is;

  • exactly as above, but with the static removed
  • file name is the same as the class name (LevelManager.cs)
  • it’s attached to a GameObject

If you still have problems I will be happy to take a look if you want to zip up the project and upload it here.

Also, check the link below regarding pasting your code into your posts - makes it easier to read :slight_smile:

See also;

Privacy & Terms