#menu start button not working

1 messages · Page 1 of 1 (latest)

fossil lion
#

I am doing a menu in unity for the first time and I want to add the play button. However the button isn't working and I can't press it

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class StartButton : MonoBehaviour
{
  public void Start()
    {
      SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
}
fallow wyvern
#

That code will just reload the menu scene, because the active scene will be the menu when it's called. Since Start() gets called at, well, the start of a script, it will immediately reload the menu. When the menu gets reloaded, it will do it again and so on. Move the scene load call to a method that is not start, and call it with the name/index of your game scene

devout wolf
fossil lion
fossil lion
#

I even tried doing it like Brackey did and put a text in the middle of the button instead of changing the sprite of the button and see if it highlights when I put the cursor on it and it didn't even highlight

fallow wyvern
#

I just noticed that you have an event system on the button, which you shouldn't. Remove that from the button and then create an event system from Create Gameobject > UI > Event System. That is probably why you can't click it

fossil lion
fallow wyvern
#

Did you create a proper event system as well as removing it from the button?

fossil lion
#

this is what I have in the inspector

fossil lion
#

Do I need to have a separate scene for the menu?

fallow wyvern
#

Is the menu not a separate scene already?

devout wolf
#

You can also program OnClick function by yourself using event system

fossil lion
# fallow wyvern Is the menu not a separate scene already?

I can click the button now,however when I start the game the game loads up without showing the menu first and I get the warning "here are 2 event systems in the scene. Please ensure there is always exactly one event system in the scene" but I only have one event system in the menu scene

#

I even tried deleting the event system in the menu scene and I still get that warning

#

also I think the problem is just that it starts with the game scene instead of menu scene

#

but the menu scene has Index 0

devout wolf
#

Don’t put the code in start make a separate function

fossil lion
devout wolf
fossil lion
# devout wolf Try to watch some other tutorials

I watched plenty tutorials, I've just never done a menu for a game and I have no idea what I've done wrong, If I hit build and run I see the menu scene for a milisecond then it moves onto the game scene