I need help, i’m making a game, and for the main menu I want to make a button to go to the first level in the title screen. Unfortunately, I’m having some trouble making a button to change the scene on the fly. Being new to Unity, I have no idea what the heck I’m doing. Can I get some help? Thank you! ![]()
If you’re not sure where to start on a problem, try breaking it down into smaller pieces. I’m confident you can find simple tutorials that show you how to write a script that changes the scene, and (separately) how to make a button that calls a script that you wrote.
Ok, I’ll try that.
So I tried it. I linked it to the button, and it seems to work with all the functions and what not, but when I click it, nothing happens. Also, the color of the button doesn’t tint. Here’s the code:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class menu : MonoBehaviour
{
public void ChangeScene (string sceneName)
{
SceneManager.LoadScene("scenename");
}
}
Did I do something wrong? Please help.
Be sure to check the Unity console for error messages. In the code you posted, it looks like you may have forgotten to replace “scenename” with the actual name of the scene you want to load.
But if there’s a problem with the button or linking up the button to your code, then I can’t diagnose that by looking at your code; I’d need details of how you created the button and linked it up. It may be more efficient for you to go back through the tutorial step-by-step and make sure you didn’t miss anything. Start by just making sure the button does something–probably whatever tutorial you are following will have some example functionality–and only worry about the scene-loading part once you have confirmed that the button itself is working.
I replaced the scenename with the scene and it didn’t work. Although, I did make a test button and nothing happened, and I think the button just isn’t working. Not even building the game worked. I put the script in a GameObject because if I just put the script in the button it would just show MONOSCRIPT STRING NAME on the functions and when i put it in the gameobject, the functions were showing. There are no errors, though. Here’s what the button’s configurations look like:

You said not even building the game worked. What happened when you tried to build?
Anything in the Unity console?
I built the game and when I clicked the button, nothing happened. I didn’t mean that it wouldn’t build the game. I should have worded that better. Sorry for the confusion.
Let’s see. That looks like a UI button. Does it have a Canvas as an ancestor? Does that Canvas have a raycaster attached?
Theoretically something could be in front of the button. One of the auto-created game objects (I think it’s the input module) will display some debug information at the bottom of the inspector if you select it while in play mode, and one of the things it lists is what the mouse is currently pointed at. Use that to make sure Unity detects you pointing at the button.
It also theoretically could be something dumb, like accidentally trying to click the button in the scene view instead of the game view. Without actually watching what you’re doing, it’d be hard to notice mistakes like that.
If you still can’t click the button, try creating a new scene, say new > UI > Button, click play, and see if that will change color for you (without adding or configuring anything else).
Oh, found the problem. There wasn’t an event system, which was weird because it would usually come with the button. Everything is working now. Thanks anyway! ![]()