Building Your First Brain Test Puzzle Logic in Unity (With Full Code)
What's Next? (Moving towards a real puzzle)
In the last tutorial, we learned how to set up Unity, create a simple 2D scene, and detect taps on objects — a huge first step toward building your Brain Test–style puzzle game. 🎯
Now it’s time to make those taps actually mean something. In this chapter, we’ll evolve our prototype into a real puzzle by introducing correct and incorrect answers, a GameManager to control game flow, and clear player feedback like “✅ Correct!” and “❌ Try Again!”.
By the end of this guide, you’ll have a functional mini puzzle system that reacts to the player’s actions — rewarding correct answers and resetting after mistakes — just like the popular mobile brain teaser games. 🧩
If you’ve followed the previous step, your project is ready. Let’s dive in and bring your puzzle logic to life. 🚀Now that we have basic tap detection working, let's evolve this into a proper puzzle. Learn how to implement puzzle logic in Unity using C#. This step-by-step guide covers tap detection, GameManager setup, feedback messages, and resetting your first Brain Test–style puzzle.
Introduce the concept of "correct" and "incorrect" objects. Implement a GameManager to track the puzzle's state. Display "Correct!" or "Try Again!" feedback. Reset the puzzle for another attempt.
Step 1: Modify
Open again in your code editor. Add a variable to the class to mark if it's the correct answer. Modify the to inform the GameManager of the tap and whether it was correct. Replace the entire content of your TapInteractable.cs script with this updated code: Save the script.
Step 2: Create the
Create In the Project window, go to your _Scripts folder. Right-click Create > C# Script. Name it GameManager.
Open in your code editor. Paste the Code: Delete all default code. Paste this code into GameManager.cs:
Save the script.
Step 3: Configure Unity Objects with the New Scripts
Attach In the Hierarchy, select the _GameManager GameObject you created earlier. In the Inspector, click Add Component. Search for GameManager and add it.
Create a Feedback Text UI: In the Hierarchy, right-click on your Canvas. Select UI > Text - TextMeshPro. Rename it FeedbackText. Select FeedbackText. In the Inspector: Rect Transform > Pos X: 0 Rect Transform > Pos Y: 0 Rect Transform > Width: 900 Rect Transform > Height: 300 TextMeshPro - Text > Text Input: Clear any default text. TextMeshPro - Text > Font Size: 100 (make it big!) TextMeshPro - Text > Align: Center (both horizontal and vertical). TextMeshPro - Text > Color: Set to White initially. Important: Uncheck the checkbox next to the FeedbackText GameObject's name in the Hierarchy. This will hide it by default.
Connect UI to Select the _GameManager GameObject in the Hierarchy. In the Inspector, under the GameManager (Script) component, you'll see new fields: For Feedback Text: Drag your FeedbackText (from the Hierarchy) into this slot. For Interactable Objects: Set the Size to 2 (since we have 2 objects for now). Drag SquareObject (from the Hierarchy) into Element 0. Drag CircleObject (from the Hierarchy) into Element 1.
Configure Select SquareObject in the Hierarchy. In the Inspector, find its TapInteractable (Script) component. Crucially, decide which one is the correct answer for your puzzle: "What object is out of place?" Let's say the Circle is out of place among squares (though we only have one square for now). So, the Circle should be the correct answer. For SquareObject, ensure Is Correct Answer is UNCHECKED. Select CircleObject in the Hierarchy. For CircleObject, ensure Is Correct Answer is CHECKED.
Save Your Scene: File > Save (or Ctrl+S / Cmd+S).
Step 4: Test Your First Puzzle!
Run the Game: Click the Play button. Test Incorrect Tap: Tap the red square. You should see "TRY AGAIN!" in red in the middle of the screen. The square should momentarily turn red (highlighting it was wrong). After a short delay, "TRY AGAIN!" should disappear, and the square should revert to its original red color.
Test Correct Tap: Tap the blue circle. You should see "CORRECT!" in green in the middle of the screen. After a short delay, "CORRECT!" should disappear, and the circle should revert to its original blue color. In the Console, you'll see a message "Puzzle Solved! Moving to next level (not implemented yet)."
A central GameManager for overall control. Interactive elements that know if they're correct. Visual and textual feedback to the player. Automatic resetting of the puzzle after an incorrect guess.
Conclusion:
Congratulations — your puzzle logic is now alive! 🥳
You’ve built a system that understands what’s right and wrong, provides instant feedback, and resets itself for the next attempt. This may seem simple, but it’s the core mechanic behind every brain teaser, riddle, and logic puzzle game.
From here, your possibilities expand fast. You can now:
-
🎨 Add more objects and make complex puzzles.
-
🔁 Load multiple levels or randomize challenges.
-
🧩 Introduce drag-and-drop, hidden clues, or timed puzzles.
-
📱 Start testing on mobile for touch interaction and polish.
In the next part, we’ll explore how to create a level system so you can move from one puzzle to the next — just like in Brain Test, Tricky Puzzle, or Who’s Lying?.
Keep experimenting, keep solving — and remember, every “Try Again!” brings you closer to “Correct!”. 💡
Comments
Post a Comment