Problems with canvas buttons in unity

后端 未结 1 666
野性不改
野性不改 2020-12-22 06:26

So, i have buttons for my game that include : Main Menu button , Restart button and Play button. Everything works fine, but occasionally one of the button\'s text doesn\'t l

相关标签:
1条回答
  • 2020-12-22 06:29

    The way your UI is setup is not right. If you have to loop through everything during pause, you are doing it wrong. I have answered a similar question before and will just copy and paste this here.

    Use different Canvas to separate your UI and group them depending on when they are displayed. Then you can toggle the whole Canvas on/off. Your [post][1] before this post shows that you are using image as button and you have a different script attached to two images you are using as buttons. Use Buttons for buttons and image for non-clickable objects. Simple as that. So change those images to buttons.

    You don't need the GameOver scene. A GameOverCanvas is fine. The GameObjects in bold are the parent Objects(Canvas). The ones under that starts with '-' are the child GameObjects.

    Step 1:

    Create Canvas and name it MainMenuCanvas (First UI to display when game Loads).Create each child button and rename them as below(GameObject->UI->Button):

    -playButton;
    -settingsButton;
    -exitGameButton;
    

    Attach the MainMenuCanvas script to the MainMenuCanvas Object.

    Step 2:

    Create a Canvas and name it GameCanvas (Displayed during game).Create each child button and rename them as below(GameObject->UI->Button):

    -pauseButton
    -jumpButton
    

    Attach the GameCanvas script to the GameCanvas Object.

    Step 3:

    Create a Canvas and name it PauseCanvas (Displayed when pause button is clicked).Create each child button and rename them as below(GameObject->UI->Button):

    -resumeButton;
    -backToMainMenuButton;
    -settingsButton;
    -exitGameButton;
    

    Attach the PauseCanvas script to the PauseCanvas Object.

    Step 4:

    Create a Canvas and name it SettingsCanvas (Displayed when settings button is clicked).Create each child button and rename them as below(GameObject->UI->Button):

    -backButton;
    

    Attach the SettingsCanvas script to the SettingsCanvas Object.

    Step 5:

    Create a Canvas and name it GameOverCanvas (Displayed when Game is Over or player is killed).Create each child button and rename them as below(GameObject->UI->Button):

    -playAgainButton;
    -backToMainMenuButton;
    -exitGameButton;
    

    Attach the GameOverCanvas script to the GameOverCanvas Object.

    Step 6:

    In the Game scene, make sure that only GameCanvas is enabled. The rest of the canvas should be manually disabled.

    Step 7:

    In the Menu scene, make sure that only MainMenuCanvas is enabled. The rest of the canvas should be manually disabled.

    Once you get this setup correctly, the UI code templates I provided should work. No more UI overlapping or text disappearing. You can easily add or remove features.

    Your UI setup should look like the image below.

    0 讨论(0)
提交回复
热议问题