Game Sample -- Piano Tiles
Development
- Inspiration
This week during our class visit to the museum, I saw this game on the displayed iPhone 4. It was one of my favorite games when I was little. Its game loop is very straightforward and clear, just like its Chinese name, “Don’t Step on the White Tile,” you simply keep pressing the black keys. It’s a speed game.
- Structure and Logic
Before getting started, I first thought about the order in which I should write the script. Since I needed many rows of tiles and wanted randomness, I couldn’t just piece together individual tiles to form a scene. So, I decided to create prefabs for the black and white tiles. With this approach, the coding logic became clear: first generate a randomized 4×4 grid of tiles, then attach C# scripts to the tiles so they can give score or failure feedback when triggered, and finally build the UI.
- Steps
1--
I first created prefabs for the white and black tiles. Then, I created an empty gameobject to carry all the C# script to generate new squares and keep the game going. In the script, I used the width and height values to generate the grid I wanted. I added randomness in the code to ensure the game’s playability.
Next, I had to figure out how to continuously generate more rows of tiles. My solution was to make the camera move up by one unit of height whenever a black tile in the bottom row was triggered. To test this idea, I experimented with OnMouseClick(): when the player clicked the black tile in the lowest row, the camera would move up by one height.
Although these approaches sound straightforward, I still struggled with it for quite a while. Sometimes clicking produced no response, other times it failed to generate a new row. Through constant failing and debugging, I gradually gained a better understanding of Unity’s interface and its functions.
I moved on to figuring out how to trigger tiles and determine win or loss. Since the original was a mobile game, I adapted it for keyboard play by assigning the four keys A, S, D, and F to represent the four columns from left to right. The code links each of these keys to the corresponding column of tiles. I then used if statements to decide whether the game continues or ends. If the correct key is pressed, the camera moves upward and a new row of tiles is generated at the top. If the wrong key is pressed, the log outputs “Game is Over.” By this point, the core gameplay loop was essentially complete.
After that, I moved on to improving the game’s UI aspects. Initially, I wanted to implement two scoring methods: one based on counting the number of correct hits, and another based on a timer that tracks the total playtime. However, I struggled with resetting the timer properly, so I had to abandon that idea. Instead, I chose to use the number of correctly pressed black tiles as the score. When the player presses the wrong key, the final score is displayed, and the score is reset to 0 at the start of the next game. One of the core features of the original Piano Tile is actually the musical effect. If I were to further improve my version, I would definitely want to add sound effects to make the game feel more authentic.
What I learn
Working on this FakeGame assignment really taught me a lot about Unity. What surprised me was that a game that looks very simple actually requires a great deal of work, continuous debugging, and repeated experimentation. I learned how to continuously spawn new game objects, how to attach C# scripts to the correct GameObjects, how to locate bugs in error messages and fix them, how to set the camera’s position and size, and how to create a UI. Each of those was a new and interesting experience for me. The development process was difficult, but finishing the project brought a strong sense of accomplishment. I have to admit I got a lot of help from GPT along the way. This experience taught me to go through my code logic again and again, find the game loop or the root of problems, and build the game step by step. Achievements and challenges go together.