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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Button Click Game

Discussion in '2D' started by unity_9TRiDWnO7W2QuQ, Sep 13, 2018.

  1. unity_9TRiDWnO7W2QuQ

    unity_9TRiDWnO7W2QuQ

    Joined:
    Apr 16, 2018
    Posts:
    3
    Hey so I want to create a little button click game where you have 2 buttons and you have to click the right one to proceed to the next level.

    So at level 1 you need to click one right level 2 two and so one.

    The sequence should be the same for every level but I have no idea how to get it working...

    Any conclussions or ideas for that topic?

    Greetings
     
  2. hamberge

    hamberge

    Joined:
    Aug 30, 2015
    Posts:
    36
    Honestly, for questions like these, you're unlikely to get an answer (except this one). Mostly because an answer requires too much effort and the information is out there. Use this as a way to teach yourself Unity.

    Start by breaking it down into the tiniest tasks you can think of. Then research each of them and implement them. Test each step you have implemented.

    So for example you could first figure out how to display a button. Then figure out how to make the button do something. Then figure out how to define what that "something" is. Etc., etc.

    Since it's just buttons, you probably want to look into the GUI. They'll have buttons and things and you can figure out how to do scripts to do the functionality that you want. The GUI is a little weird to learn in the beginning but once you have done it for a little while, it makes a lot of sense.

    Have fun learning Unity!
     
    MisterSkitz likes this.
  3. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    You're going to need variables to keep track of your right answers and perhaps wrong answers.
    Then you'll need to create 2 UI buttons (Which Unity does provide).
    Create a script the handles the logic. Maybe one script is a giant dictionary that stores all the questions/answer? Then another script that determines what to do if right/wrong/ or progression.

    How well are you at coding? I'm willing to help you get started.
     
  4. chemimartinez77

    chemimartinez77

    Joined:
    Apr 8, 2016
    Posts:
    25
    He didn't say it's a questions/answers game. Two buttons. Seems quite simple but... simple for one who knows how to code and knows some Unity as well. I think @hamberge is right. Even if the game looks that simple, the answer he's looking for is way too complex to explain here.

    Regards!
     
    MisterSkitz likes this.
  5. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    No, I totally agree with you both. I'm just bored and in an extra helpful mood this morning :)
     
    chemimartinez77 likes this.
  6. chatrat12

    chatrat12

    Joined:
    Jan 21, 2015
    Posts:
    122
    I got you

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class SimpleButtonGame : MonoBehaviour
    4. {
    5.     private int _level = 0;
    6.  
    7.     private void OnGUI()
    8.     {
    9.         GUILayout.BeginVertical();
    10.         GUILayout.Label(string.Format("Level {0}", _level + 1));
    11.  
    12.         GUILayout.BeginHorizontal();
    13.         var buttonClick = -1;
    14.         if (GUILayout.Button("Left"))
    15.             buttonClick = 0;
    16.         if (GUILayout.Button("Right"))
    17.             buttonClick = 1;
    18.         GUILayout.EndHorizontal();
    19.  
    20.         if(buttonClick >= 0)
    21.         {
    22.             // Picking the winning button on the fly
    23.             if (buttonClick == Random.Range(0, 2))
    24.                 // Advance level :D
    25.                 _level++;
    26.             else
    27.                 // You lose :(
    28.                 _level = 0;
    29.         }
    30.         GUILayout.EndVertical();
    31.     }
    32. }
    Keep in mind, this is not how you would do GUI in an actual game. IMGUI is deprecated but its an easy starting off point for learning the ropes to program game logic. This game is super basic and bare bones. You could try adding a reset button when you lose. Maybe keep track and display the high score. Try it out!