How to Create a Brain Test–Style Puzzle Game in Unity (Step-by-Step Guide for Beginners)
I will guide you step-by-step through the process of setting up Unity and creating your first "Brain Test" style puzzle.
Let's Begin: Unity Setup and Your First Interactable Object
Install Unity and create a new 2D project. Set up the basic UI Canvas for your puzzle. Create a simple image that the player can tap. Write a script to detect taps on that image.
Step 1: Install Unity and Create a New Project
Download Unity Hub: Go to the official Unity website: https://unity.com/download Click "Download Unity Hub" and install it on your computer.
Install a Unity Editor Version: Open Unity Hub. Go to the "Installs" tab on the left. Click "Install Editor." I recommend installing the latest LTS (Long Term Support) version (e.g., Unity 2022.3.x LTS). LTS versions are more stable and supported for longer. Make sure "Android Build Support" and "iOS Build Support" are checked under the modules, as your GDD specifies these platforms. Click "Install." This might take a while.
Create a New Unity Project: Once an Editor version is installed, go to the "Projects" tab in Unity Hub. Click the "New Project" button. In the templates list, select "2D Core". Under "Project Name," type: TrickyLogicPuzzle Choose a convenient "Location" on your computer. Click "Create project."
Unity will now open, and it might take a few minutes to import all the necessary assets. Be patient!
Step 2: Basic Project Structure and UI Canvas Setup
Project Organization (Folders): In the Project window (usually at the bottom), right-click on the Assets folder. Select Create > Folder. Name the new folder _Scenes. Repeat this process to create the following folders: _Scripts, _Sprites, _UI, _Audio, _Prefabs. (The underscore _ helps them sort to the top).
Save Your Current Scene: Go to File > Save As... Navigate into your newly created _Scenes folder. Name the scene GameScene and click Save.
In the Hierarchy window (usually on the left), right-click anywhere. Select UI > Canvas. This will create three new objects: Canvas, EventSystem.
Configure the Canvas: Select the Canvas object in the Hierarchy. In the Inspector window (usually on the right), find the Canvas component. Change Render Mode from Screen Space - Overlay to Screen Space - Camera. Drag your Main Camera from the Hierarchy into the Render Camera slot that appears on the Canvas component in the Inspector. Find the Canvas Scaler component (still on the Canvas object). Change UI Scale Mode from Constant Pixel Size to Scale With Screen Size. Set Reference Resolution to 1080 (width) and 1920 (height) – this is a common portrait resolution for mobile. Set Match to 0.5 (this balances scaling between width and height).
Your Game view (usually in the middle) should now show a canvas that adapts to different screen sizes.
Step 3: Add Text for the Puzzle Question
Install TextMeshPro Essentials: Go to Window > TextMeshPro > Import TMP Essential Resources. Click Import in the pop-up window. This replaces Unity's default UI text with a much better text rendering system.
Add Puzzle Question Text: In the Hierarchy, right-click on your Canvas object. Select UI > Text - TextMeshPro. This will create a New Text (TMP) object as a child of Canvas. Select New Text (TMP) in the Hierarchy. In the Inspector, rename it to QuestionText. In the Rect Transform component, set: Pos X: 0 Pos Y: 800 (This puts it near the top of the screen) Width: 900 Height: 200 You can drag the blue square handles in the Scene view to resize it if needed.
In the TextMeshPro - Text component, for the Text Input field: Type: What object is out of place? (This will be our first simple puzzle question). Set Font Size to 60. Click the Align buttons to set Center for both horizontal and vertical alignment.
Step 4: Create a Simple Image for Interaction
Add a Square Image: In the Hierarchy, right-click on your Canvas. Select UI > Image. Rename this Image to SquareObject. Select SquareObject. In the Inspector: Rect Transform > Pos X: -200 Rect Transform > Pos Y: 0 Rect Transform > Width: 200 Rect Transform > Height: 200 Image (Script) > Color: Click the color picker and choose a distinct color (e.g., Red).
Make sure "Raycast Target" is checked on the Image component. This allows it to receive touch input.
Add a Circle Image: In the Hierarchy, right-click on your Canvas. Select UI > Image. Rename this Image to CircleObject. Select CircleObject. In the Inspector: Rect Transform > Pos X: 200 Rect Transform > Pos Y: 0 Rect Transform > Width: 200 Rect Transform > Height: 200 Image (Script) > Color: Click the color picker and choose a distinct color (e.g., Blue). Click the small circle next to the Source Image field. In the popup, search for Circle and select UI/Skin/Knob. This will make it a circular image.
Make sure "Raycast Target" is checked.
Save Your Scene: File > Save (or Ctrl+S / Cmd+S). You should now see your question text, a red square, and a blue circle in your Game view.
Step 5: Write the Tap Detection Script
Create a Script: In the Project window, navigate to your _Scripts folder. Right-click in the _Scripts folder. Select Create > C# Script. Name it TapInteractable. Make sure the name is exactly
Open the Script: Double-click TapInteractable in the Project window. This will open it in your code editor (Visual Studio by default).
Paste the Code: Delete all the default code in the file. Paste the following code into TapInteractable.cs:
Save the Script: File > Save (or Ctrl+S / Cmd+S) in your code editor.
Step 6: Attach the Script to Your Objects
Attach to SquareObject: Go back to Unity Editor. In the Hierarchy, select SquareObject. In the Inspector, click Add Component. Search for TapInteractable and select it.
Attach to CircleObject: In the Hierarchy, select CircleObject. In the Inspector, click Add Component. Search for TapInteractable and select it.
Save Your Scene: File > Save (or Ctrl+S / Cmd+S).
Step 7: Test Your First Interaction!
Run the Game: Click the Play button (the triangle) at the top center of the Unity Editor. The Game view will become active.
Tap the Objects: Click on the red square in the Game view. Look at the Console window (usually at the bottom, next to Project). You should see: SquareObject was tapped! The SquareObject should also turn green. Click on the blue circle. You should see: CircleObject was tapped! The CircleObject should also turn green.
Stop the Game: Click the Play button again to stop the game. Notice that the colors will revert to their original state because changes made in Play Mode are temporary.

Comments
Post a Comment