Claude & Unity Fruit Catcher (part 1): move a basket with the arrow keys and drop fruit from the sky

Translated from the original Traditional Chinese version.

Summary

Building a small game you can play is a good way to learn Unity, and the Fruit Catcher’s rules are simple enough to practice scenes, prefabs, and the Inspector. We split the game into four stages. At each stage you give Claude a prompt, Claude writes the code and places the objects, and you check the result in the Editor and press Play. This article covers the first two stages: a basket that follows the left and right arrow keys, and fruit and bombs that fall from random spots in the sky.

Table of contents

After you install Unity and create a project, the next step is to make a game you can actually play. The rules of the Fruit Catcher fit in one sentence: move a basket left and right with the arrow keys, catch the fruit that falls from the sky, and avoid the bombs. The rules are simple, but the game already uses the most common things Unity games do: placing objects in a scene, reading keyboard input, spawning copies of an object from a prefab, and letting gravity pull objects down.

We split the game into four stages and give Claude one prompt for each stage. Claude does the code and the scene. You check in the Editor what Claude did, then press Play to try the game. This article covers the first two stages. When you finish, the basket follows the arrow keys, and fruit and bombs fall from random spots in the sky, but the basket can’t catch anything yet. The next article adds catching, scoring, and Game Over.

The Game view at the end of stage 2: a banana, an apple, and a bomb rest on the basket, and another apple is still falling

This article follows Claude & Unity version control and uses the same workflow: Claude creates a branch and opens a pull request for every change, and you review and merge it. The project at the end of each stage is in the Fruit Catcher example project on GitHub, separated by tags, so you can look at it when yours differs. I tested on Windows 11 and Unity 7000.0.0a23 (Alpha).

Create the Fruit Catcher project

We build the Fruit Catcher in a new project. In the Code tab of the Claude desktop app, choose the C:\UnityGames folder, start a new session, and type the prompt below. I wrote my prompts in Chinese, and the prompts in this article are the English equivalents.

1Create a Unity 7 project named claude-unity-fruit-catcher from the Universal 3D template, and don't connect it to Unity Cloud. Then write a new CLAUDE.md based on the one in MyFirstGame, and add folder and naming rules: scenes go in Assets/Scenes, scripts in Assets/Scripts, prefabs in Assets/Prefabs, and materials in Assets/Materials; names are English PascalCase with no spaces; don't store the score or lives in static fields; use the Input System for input. Finally, create a Git repo and a private GitHub repo, and push to it.

Claude creates the project with the Unity CLI, copies .gitignore from MyFirstGame, writes CLAUDE.md and commits, then creates a private GitHub repo and pushes to it. In my test the whole run took about 3 minutes, and at the end Claude reported the project location, the repo URL, and the rules in CLAUDE.md. Claude may also add a few rules of its own. In my test it added “don’t put new files in the Assets root” and “one MonoBehaviour per file”, so open CLAUDE.md once and make sure every rule is one you want.

Claude also pointed out two things, and you don’t need to act on either. First, Assets/Scripts, Assets/Prefabs, and Assets/Materials don’t exist yet, because Git doesn’t track empty folders. They appear when the first file goes in. Second, the template’s Assets/Settings/Build Profiles (with a space) and Mobile_RPAsset.asset (with an underscore) break the new naming rules, but they are the template’s settings files, so Claude left their names alone.

The full explanation of the folder and naming rules in CLAUDE.md is in Organizing a Unity 7 project’s folders. With the rules written down first, the files Claude adds at every later stage go in fixed places, and you know where to look when you check them.

Move the basket with the arrow keys

Stage 1 builds the scene and the basket. In the same session in C:\UnityGames\claude-unity-fruit-catcher, type:

1Help me start the first step of a Fruit Catcher game. First delete the TutorialInfo folder, the Readme, and SampleScene that came with the template, and rename the main scene to Assets/Scenes/FruitCatcher.unity. Keep the template's camera, light, and Global Volume.
2
3In the scene, put a green ground, a sky-blue background, two trees made from a cylinder and a sphere, and a wood-colored basket. Group and name the objects following the rules in CLAUDE.md, and save them directly in the scene. Don't write a script that generates the scene with one click. Then write a BasketController script that uses the Input System to read the arrow keys and A/D and move the basket left and right. The basket must not leave the screen, and the speed must be adjustable in the Inspector.

The prompt says “save them directly in the scene” because Claude sometimes writes an Editor script that generates the scene. A scene made that way only appears after you run the script, and in the Hierarchy you can’t see how each object was placed.

Claude creates three materials and the BasketController script, places the objects in the scene and saves it, and then follows CLAUDE.md to create a branch and open a pull request. You merge the pull request on GitHub the same way as in Claude & Unity version control.

After you merge, check three things in the Editor. First, the objects in the Hierarchy are grouped under Environment and Gameplay. Unity 7 Hierarchy basics explains how grouping works:

The Hierarchy after stage 1: Environment contains Ground, Background, TreeLeft, and TreeRight, and Gameplay contains Basket

Second, select Basket in the Hierarchy. The Inspector shows a Basket Controller component, and its Speed field sets how fast the basket moves:

The Inspector for Basket, with Transform, Box Collider, Mesh Renderer, and Basket Controller components, and Speed set to 10

Third, press Play and move the basket with the arrow keys or A and D. The basket stops at the edge of the screen:

The Game view after pressing Play in stage 1: two trees and an orange basket on the grass, with no fruit yet

If the basket moves too fast or too slow, stop Play first, then change the value of Speed in the Inspector. A value you change during Play goes back to the old value when you stop. That makes Play a good way to find a speed you like. After you find it, stop Play and enter it again.

Drop fruit from the sky

Stage 2 makes fruit and bombs fall from the sky. In the same session, type:

1Next, make things fall from the sky. Make three prefabs: an apple, a banana, and a bomb. Basic shapes with materials are enough: the apple is red, the banana is yellow, and the bomb is black. Each one needs a Rigidbody so gravity pulls it down, and a Collider.
2
3Then make a FruitSpawner and put it under Gameplay. At regular intervals it spawns one of the three at a random X position above the screen, and the interval must be adjustable in the Inspector. Delete anything that falls below the ground so they don't pile up.

Claude creates two scripts, FallingItem and FruitSpawner. FallingItem goes on every prefab and deletes its object once it falls below the ground. FruitSpawner spawns objects at the interval you set.

A prefab is an object template saved as a file. Each time FruitSpawner spawns fruit, it copies a new object from the prefab. To change the size or color of the fruit, you change the prefab, and every fruit spawned afterward changes with it.

After you merge, open Assets in the Project window. Claude followed the rules in CLAUDE.md and put the prefabs in Prefabs and the materials in Materials:

The Project window at stage 2, listing six materials (Apple, Background, Banana, Basket, Bomb, Ground) and three prefabs (Apple, Banana, Bomb)

Click Apple in the Prefabs folder, and the Inspector shows its components. The Rigidbody lets gravity pull the apple down. The Collider is the shape Unity uses when objects touch. The next article uses it to decide whether the basket caught the fruit:

The Inspector for the Apple prefab, with a Sphere Collider, a Rigidbody with Use Gravity checked, and a Falling Item component

Select FruitSpawner in the Hierarchy, and the Inspector lists the prefabs to spawn, plus “Spawn Interval” (seconds between spawns), “Spawn Height” (the spawn height), and “Spawn Range X” (the left-right spawn range):

The Inspector for FruitSpawner: the Prefabs list contains Apple, Banana, and Bomb, Spawn Interval is 1.2, and Spawn Height and Spawn Range X are both 9

After you press Play, fruit and bombs fall from different positions above the screen. They pass through the ground, leave the screen, and disappear from the Hierarchy. Anything that lands on the basket stays on it, because the basket is still solid at this point. Stage 3 in the next article changes the basket so it can catch things.

Compare with the example project

If what you built looks different from this article, compare it with the example project. It has one tag at the end of each stage:

Tag What it contains
stage-1-basket The scene, ground, background, and a basket that moves
stage-2-fruit The fruit and bomb prefabs and the spawner

On the example project’s GitHub page, switch to either tag to see the files at that point. The README also lists the full prompt for each stage, the files it adds, and what to check in the Editor. The code Claude writes is not always identical to the example. As long as the game behaves the same when you press Play, it is fine.

Test notes

Item Details
System Windows 11, physical machine
Editor Unity 7000.0.0a23 (Alpha)
Template Universal 3D (com.unity.template.urp-blank)
Example tedliou/claude-unity-fruit-catcher

I tested the “create the project” prompt in a separate Claude Code session outside the desktop app. I pasted it as written in C:\UnityGames and changed only the project name to a test name. Claude created the project with unity projects create plus --template com.unity.template.urp-blank and --no-cloud. It pushed the first commit straight to main, and later changes follow CLAUDE.md and go on branches.

After each stage I merged the pull request and played the game. The Console had no errors in either stage:

Stage How I tested Result
stage-1-basket Held the arrow keys and A and D The basket moves left and right and stops at the screen edge
stage-2-fruit Pressed Play and watched All three objects spawn at random spots, and they disappear from the Hierarchy after they fall below the ground

The first time I built this, the sky-blue background was too close to the trees, and the trees cast shadows on it. I asked Claude to move the background back and stop it from receiving shadows, and the shadows went away.

Summary

After these two stages, the next article, Claude & Unity Fruit Catcher (part 2), lets the basket catch fruit, add to the score, and take away lives, which makes a complete game you can replay. At every stage Claude writes the code and places the objects, and you only check the result in the Hierarchy, the Inspector, and the Play view.

Further reading

Ted Liou

Ted Liou

Software engineer writing about Unity and AI development.

Comments