The Level Manager won’t show in function for start button.
Did you set your method to be public? Paste your code up and lets take a look
Hi there! I also answered this on Udemy, but just in case anyone needs it, I’ll leave it here as well:
The problem could have something to do with the warning I notice you’re getting in the console (in the second picture, very bottom of the screen):
Assets/LevelManager.cs(8,29): warning CS0616: ‘UnityEngine.Application.LoadLevel(string)’ is obsolete: use SceneManager.LoadScene’
This is pretty self explanatory really. If you’re using Unity 5 (like I am), you need to replace the line in your LevelManager where you have:
Application.LoadLevel(name);
with
SceneManager.LoadScene(name);
At the very top of the LevelManager script, you also need to import the SceneManagement system:
using UnityEngine.SceneManagement;
Hope it helps!
One possibility: you need to put an actual game object in for "OnClick", one that has the script as a component, rather than the script itself. I don't know if a prefab will work--I think it has to be a gameobject that is "alive" in the scene.
You’re spot on there @Todd_Vance, I didn’t even notice the little script icon! doh!
Just tested this and created the same issues as above.
I am having the same problem. I doubt anybody checks this chat but if someone comes across it please help as I have no idea how to get the LevelManager program to work. It worked fine in NumberWizard.
To clarify, I have tried using the scenemanager method and that didnt work. And all my functions are public. I am in unity 4.6.x
Hi Oscar,
In order for your LevelManager’s methods to be available in the OnClick events for the buttons you’ll need to have a GameObject in the Hierarchy (ideally perhaps named LevelManager) and attach the LevelManager.cs script to it.
If you are receiving warnings (yellow triangle) about the Application.LoadLevel
method, this isn’t a significant problem. If you are receiving errors (red exclamation marks), then that is an issue.
Let me know what you have so far, perhaps a screenshot from Unity also and we can go from there - let’s get you back on track
Hi Oscar,
Ok, so you have the GameObject in the Hierarchy and it has the script attached and there are no noticeable warnings or errors at this stage.
Can you select your Start
button in the Hierarchy and then pop a screenshot up of the details from the Inspector, specifically the OnClick()
event handlers section, but ideally the entire Inspector view.
Hi Oscar,
Can you drag the LevelManager from the Hierarchy into the object field in the OnClick()
event you currently have set up, I have highlighted this field in the copy of your screenshot below;
Then click on the button which exposes the methods again.
Is it working correctly now?
Oh, well that worked. Why did it not work directly from the script?
Anyway thanks for the help, the support in this course is at a much higher quality than I expected.
Oh, well that worked. Why did it not work directly from the script?
Sorry for the delay responding.
The reason it didn’t work is because your script needs to be attached to a GameObject in order to be executed, so, when you had dragged only the script to the object field previously, it effectively didn’t exist in the scene.
When you dragged the LevelManager GameObject, with the script attached as a component, the script is now in the scene, Unity is able to see the methods that this class exposes.
Hope this helps
Anyway thanks for the help, the support in this course is at a much higher quality than I expected.
You’re very welcome Oscar and thank you, that’s really nice to hear
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.