Game manager is broken

For some reason when I try to ad the game manager to the list it only adds the OnReplayLevel command how can I fix this

Your code seems broken. You have a GameManager component on the button, but the script is OnReplayLevel. Then you also have a GameManager game object in the hierarchy.

Please share the contents of the GameManager.cs file


Sorry for long reply took a break

Hi odinn,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

In your code, I can see only one method (apart from Start and Update): OnReplayLevel. What did you expect to see in Unity?

Make sure a game object is attached to the OnClick field, not the script itself. Also make sure to select a Function. In your first screenshot, the drop down menu says “No Function”.

If nothing helped, I would recommend to rewatch the video at least one more time. Maybe a detail is missing in your game.

Hope this helped. :slight_smile:


See also:

The two screenshots don’t match up. My response earlier was based on this observation
image

This shows that the script is called OnReplayLevel. But the screenshot you posted with the code does not reflect this.

Wow, good catch! I didn’t even notice that.

Sorry but I don’t understand?

I’m saying something has changed between the two screenshots. Your first screenshot shows that there is a file called GameManager.cs which contains a class called OnReplayLevel, but your screenshot of the GameManager.cs does not show this. This may have been Unity bugging out.

If you go to your inspector, remove the 'GameManager` component from the button. It shouldn’t be there.

image

Then, drag the GameManager from the hierarchy to the button

This should now say ‘GameManager’ instead of ‘OnReplayLevel’. Now you will be able to click the dropdown, find ‘GameManager’ and in it’s sub menu you’ll see ‘OnReplayLevel’

image

It works but there is no sub menu
Screenshot (15)

Can you show the GameManager’s inspector?

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour

{

Quiz quiz;

EndScreen endScreen;

void Start()

{

    quiz = FindObjectOfType<Quiz>();

    endScreen = FindObjectOfType<EndScreen>();

    quiz.gameObject.SetActive(true);

    endScreen.gameObject.SetActive(false);

}

void Update()

{

    if(quiz.isComplete)

    {

        quiz.gameObject.SetActive(false);

        endScreen.gameObject.SetActive(true);

    }

}

public void OnReplayLevel()

{

    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

}

}

does this work or do you want a screenshot?

No, I want to see the GameManager in the hierarchy’s inspector.

Still not the one. I want to see the GameManager game object, not the script


This one?

There’s something wrong in here that I’m just not seeing. Please right-click on the GameManager script and choose “Reimport All” from the menu

image

It didn’t fix anything :anguished:

Six more things you could try:

  1. Go to Edit > Preferences > External Tools and click “Regenerate project files”.

  2. Close Unity and Visual Studio Code. Go to your project folder and delete the Library folder and the Temp folder if you see them. Launch Unity again. This might take a while because Unity will recreate the Library folder. Then open your scene because Unity will very likely open its empty default scene.

  3. Delete the Button component, readd it and drag and drop the GameManager game object into the OnClick field as shown by bixarrio.

  4. Launch Unity with administration rights.

  5. Do you use an antivirus program or a firewall that might be blocking Unity?

  6. Update Unity to the latest stable version.

  7. I’m wondering why your GameManager script(?) has got a cogwheel icon in the Assets folder. Did you change that or has it always been like that? If not, rename GameManager to GameHandler. Do that for both the file and the class.

It’s a Unity thing. Unity changes GameManager scripts to have a cog

Thanks for the information. I’ve just found a thread about that. Seems to be an ancient problem(?). I’m wondering if the name GameManager causes any issues in this game.