Table of contents

In the previous article you built the scene, a basket that moves with the arrow keys, and fruit and bombs that fall from random spots in the sky. When one lands on the basket it just sits there. That is not a catch yet. This article finishes the last two stages of the Fruit Catcher. Stage 3 lets the basket tell whether it caught fruit or a bomb. Stage 4 adds a score, three lives, a Game Over screen, and a restart on R. When you finish, you can play the Fruit Catcher through to Game Over and start over with R.

This article follows Claude & Unity Fruit Catcher (part 1) and keeps using that project and session. As before, Claude opens a pull request for each stage. You merge it on GitHub, then check the result in the Editor. I tested on Windows 11 and Unity 7000.0.0a23 (Alpha).
Let the basket tell what it caught
A Collider is the invisible shape Unity uses to detect whether two objects touch. The fruit from part 1 already has a Collider, and the basket has a solid Box Collider, so things stop on top of the basket. This stage checks “Is Trigger” on the basket’s collider. A Collider with Is Trigger checked doesn’t bounce the fruit away. It only notifies the code when the fruit enters its area, which is what we need to detect a catch.
Fruit and bombs are told apart by Tag. A Tag is a label on an object. The code reads the Tag of the object it touched, Fruit or Bomb, and knows whether to add points or take away a life. In the session with Claude, type:
1Now let the basket catch things. Change the basket's Box Collider to Is Trigger, add a Rigidbody with Is Kinematic, and use OnTriggerEnter to detect what it caught.
2
3Set the Tag of the apple and banana to Fruit, and the Tag of the bomb to Bomb. Whatever it catches should disappear. For now, just use Debug.Log to print in the Console what was caught. We'll do the score later.
OnTriggerEnter is a method that Unity calls automatically, like Update. It runs when something enters the Trigger’s area. The order in which Unity calls these methods is in Unity 7 script execution order. Unity calls it only when both objects have a Collider, at least one of them is a Trigger, and at least one has a Rigidbody (OnTriggerEnter in the manual). A Rigidbody is the component that lets Unity’s physics move an object. The fruit already has one. Adding a Rigidbody with “Is Kinematic” checked to the basket means the code moves the basket, and gravity doesn’t make it fall.
After you merge, select Basket in the Hierarchy. In the Inspector, the Box Collider has Is Trigger checked:

Press Play and catch a few fruits and bombs. The Console prints what you caught each time:

If the Console prints these messages, the catch detection works. There is nowhere to show the score yet, so the next stage replaces the messages with a real score.
Add a score, lives, and Game Over
Stage 4 adds the game rules and the on-screen text. Keep typing in the same session:
1Finally, turn this into a complete game. Make a GameManager that tracks the score and lives: catching an apple adds 10 points, catching a banana adds 15, you start with 3 lives, missing a fruit or catching a bomb takes away 1 life, and when the lives run out, show Game Over, and restart with SceneManager.LoadScene when I press R. Don't store the score or lives in static fields.
2
3Create the on-screen text with the menu "GameObject > UI (Canvas) > Text - TextMeshPro", then write a ScoreUI script that shows the score, the lives, and Game Over. Use English for the text in the game. Also make the fruit fall a little more often every 15 seconds, and stop spawning after Game Over.
The prompt names a menu because that is how you would add the text yourself. Claude can’t click Unity’s menus, so it creates the objects the menu would create: a Canvas, an EventSystem, and the TextMeshPro text.
The prompt also says “Don’t store the score or lives in static fields” because a new Unity 7 project doesn’t reload scripts when you press Play, so a static value carries over to the next Play. The reason is in Unity 7 C# scripting basics. The score lives on the GameManager object. When you press R and reload the scene, Unity creates GameManager again, and the score goes back to 0.
The on-screen text uses TextMeshPro. In Unity 7, TextMeshPro is included in the uGUI package. The first time you create text, no window asks you to import fonts, and no TextMesh Pro folder appears under Assets. Select a text object that Claude created, and the “Font Asset” in the Inspector is already the DefaultFont that comes with the package:

After you merge, the top level of the Hierarchy has two new objects, UI (which holds the Canvas and the text) and GameManager. Select GameManager in the Hierarchy, and the Inspector shows “Start Lives” (the number of lives you start with) and “Score UI” (the object that shows the score):

The values that control difficulty are in three places. To adjust them, change the numbers in the Inspector:
| Value to change | Where to change it |
|---|---|
| Starting lives | Start Lives on GameManager |
| Points for each fruit | Points on the Falling Item component (from part 1) of Apple and Banana in the Prefabs folder |
| How often things fall | Spawn Interval on FruitSpawner (the spawner from part 1), and Speed Up Every, which sets how many seconds pass between speed-ups |
Play the complete game
Press Play and play from the start. If the rules are correct, you see these four results:
- Catching an apple adds 10 to the score, and catching a banana adds 15.
- Missing a fruit or catching a bomb takes 1 off the lives in the upper right.
- When the lives run out, the screen shows Game Over, and the fruit stops falling.
- After you press R, the game starts again, with the score back at 0 and the lives back at 3.

If the score doesn’t reset after you press R, the score may be stored in a static field. Ask Claude to store it on the GameManager object, following the rules in CLAUDE.md (the project rules file from part 1). If the Console shows a red error, paste the error message to Claude, ask it to fix the problem, and have it open another pull request.
Check your project against the example
As in part 1, the last two stages are tagged in the example project. To see one, clone or download the repository and run git checkout stage-3-catch or git checkout stage-4-score:
| Tag | What it contains |
|---|---|
stage-3-catch |
The basket’s Trigger and the Tags on fruit and bombs |
stage-4-score |
Score, lives, Game Over, restart, and gradual speed-up |
The main branch of the Fruit Catcher example project on GitHub now contains stage 5 as well (lights, post-processing, particles, and sound). To play the game as it is after this article, check out stage-4-score.
Test notes
| Item | Details |
|---|---|
| System | Windows 11, physical machine |
| Editor | Unity 7000.0.0a23 (Alpha) |
| Example | tedliou/claude-unity-fruit-catcher |
I merged both stages and played the game after each one. The Console had no errors:
| Stage | How I tested | Result |
|---|---|---|
| stage-3-catch | Moved the basket under the falling objects | Apples, bananas, and bombs all triggered a catch, and the Console printed one message for each catch |
| stage-4-score | Left the basket still, chased the fruit, caught one bomb on purpose, and pressed R | Three misses ended the game with Game Over, an apple added 10, a banana added 15, and a bomb took lives from 3 to 2 |
| stage-4-score | Watched the spawn interval | At 15 and 30 seconds, the interval went from 1.2 seconds to 0.96 seconds, then to 0.768 seconds |
| stage-4-score | Pressed R after Game Over | The falling objects on screen were cleared and spawning stopped. After R, the game was back to Score 0 and Lives 3 |
Summary
After all four stages, the game is complete: you play until Game Over, then press R for another round. To change the difficulty later, change the values on GameManager and FruitSpawner in the Inspector. Across all four stages Claude wrote five scripts: BasketController, FallingItem, FruitSpawner, GameManager, and ScoreUI. Each file name tells you what the script does.

