Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Button Not Working

Discussion in 'Getting Started' started by carlsonz16, May 29, 2020.

  1. carlsonz16

    carlsonz16

    Joined:
    May 13, 2020
    Posts:
    3
    I had no idea what thread to put this in, but I have a game in development right now and I have a level complete scene that is hidden in the scene at first but becomes seen once the player reaches a certain point. On that panel I have 2 buttons, 1 for main menu and 1 for the next level. Whenever I play my game however, the button don't work at all. Is this because buttons don't work in the scene if hidden at first? Here is my code and a screenshot of my scene. Thanks.

    public void NextLevel()
    {
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    level = level + 1;
    }

    public void MainMenu()
    {
    SceneManager.LoadScene(0);
    level = 0;
    }

    upload_2020-5-29_15-50-27.png
     
  2. ProntName

    ProntName

    Joined:
    Apr 27, 2020
    Posts:
    15
    Is the LevelComplete script attached to the “LevelComplete” object that’s inactive? That might be the problem. Try removing the script from there and placing it on your Canvas object and see if that works.

    I know that Unity is finicky about calling scripts from inactive objects.