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
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.
See also:
- Forum User Guides : How to apply code formatting within your post
- Forum User Guides : How to mark a topic as solved
The two screenshots donât match up. My response earlier was based on this observation
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.
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â
It works but there is no sub menu
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.
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
It didnât fix anything
Six more things you could try:
-
Go to Edit > Preferences > External Tools and click âRegenerate project filesâ.
-
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.
-
Delete the Button component, readd it and drag and drop the GameManager game object into the OnClick field as shown by bixarrio.
-
Launch Unity with administration rights.
-
Do you use an antivirus program or a firewall that might be blocking Unity?
-
Update Unity to the latest stable version.
-
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.