Dragging LevelManager Script into 'On Click' for the Button Does Not List Functions

Hi,

If I drag the LevelManager script into the OnClick section of the button, and then search for functions, there is no LevelManager option to choose from. I did change the function to public.

Any idea why?

LevelManager Script

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class LevelManager : MonoBehaviour {

// Use this for initialization
void Start () {
    
}

// Update is called once per frame
void Update () {
    if (Input.GetKeyDown("space"))
    {
        LoadNextScene();
    }


}

public void LoadNextScene() {
         
            int currentIndex = SceneManager.GetActiveScene().buildIndex;
            //Load currentIndexIndex + 1
            SceneManager.LoadScene(currentIndex + 1);

    }

}

Inspector

Screenshot and post code :slight_smile:

Oh yeah it was late and I forgot to do that. It’s up now!

could you post a picture of your inspector too please

Yup. It’s uploaded. You will need to click and expand to see the whole image

You know where it says ‘No Funciton’, have you tried clicking on it? It’s a drop down menu, it should show the Level Manager?

Yeah there is nothing there. The only option is MonoScript —> String Name

Actually, try making an empty game object, name it LevelManager.

Drag your LevelManager script onto this newly created game object.

Then try dragging to LevelManager GameObject onto the OnClick part. See if the other options come up.

Yeah I actually already did this too. The OnClick event is in my buttons inspector which is posted above.

Uploaded images of my hierarchy and LevelManager in the inspector

But can I confirm, on the Button Gameobject, the OnClick event, you have dragged the LevelManager Gameobject to it, NOT the levelmanager script?

Yessir

I created a new gameobject, put a script onto it, and I dragged the game object onto the On Click part.

Can you see my LevelManager bit? I have a blueish cube. It is because I dragged my game object that has the script onto the button gameobject.

AHHHHHH OMG lol. After reading your last post, I re-read your previous post and realized I actually did not do the thing you were checking for. I did put the script on the OnClickEvent, not the game object. It works now.

Thanks for helping me troubleshoot this lol

2 Likes

LOLOLOL

I actually had a feeling you were doing that :smiley: :smiley: :smiley:

But no worries, all part of the learning process :wink:

3 Likes

Can anyone tell me why I am seeing all these functions under my LevelManager Game Object?
image

Hi,

Your LevelManager is inheriting from MonoBehaviour, thus its public methods/fields/properties will be available also.

Hope this helps. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms