Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

UI Button

Hi, I'm very new to Unity and making games so I decided to start with a basic 2d puzzle dice game. What I'm stuck on at the moment is to make my UI button let the player know if they have the correct answer to the puzzle when pressed. In the puzzle the player clicks on a sprite button to change the dice face from 1 to 6 and when they think they have the correct dice face number, they click on the UI "Done" button and if correct they go to the next level or if incorrect they repeat the level they are on. I don't know how to get the my "Done" button to do that?

Any help will be appreciated. Thanks

Comments

  • Are you reffering to getting a UI Button to run part of your code or do you need help getting the button to only continue when the puzzle is complete? Or if it is something else. I'll answer both of those here as I'm unsure.

    To have a UI Button run code, in the inspector there is a box that says OnClick() and then has an empty list below it. Click on the plus sign, and then in the object field drag in the object that has the script that lets you carry on to the next level. Then in the dropdown list you can choose any function that you want to run within that script when the button is clicked, but only if it is public.

    For checking if the puzzle is complete, what I would recommend is that within one of your scripts you have a variable called "isCorrect" or something like that. When the player has the correct dice face number, that variable switches to true. Then, in your button script, you can check to see if that is true; if it is, then continue on to the next level, or if not then don't.


    Hopefully that helps, let me know if I don't understand the question properly.

  • wah2068wah2068 Member

    The puzzle has dice faces and a blank one for the player to click through dice face 1 to 6, when the player thinks they have the correct dice number they click on the "Done" button and if correct they go to the next level or if they are incorrect they redo the level they are on. I'm very new at this and thought this would be a basic game to start off with to learn more on how to make games. At the moment it's a bit difficult to grasp C# but I'm sure I'll get a hang of it, I've learned a bit and like I said, new at this. It's just working out the UI "Done" button to know if the sprite dice face button has the correct dice number on it.

    I've worked out the multi click button press for the dice face buttons and having sound connected to them but I seem to be stuck on this problem at the moment. Anyway, thanks for your reply and I do appreciate any help or tips.


    Thanks

Sign In or Register to comment.