Challenge 5 - Whack-a-Food Game
Tutorial
·
Beginner
·
+10XP
·
60 mins
·
(19)
Unity Technologies

Challenge Overview:
Put your User Interface skills to the test with this whack-a-mole-like challenge in which you have to get all the food that pops up on a grid while avoiding the skulls. You will have to debug buttons, mouse clicks, score tracking, restart sequences, and difficulty setting to get to the bottom of this one.
Challenge Outcome:
- All of the buttons look nice with their text properly aligned
- When you select a difficulty, the spawn rate changes accordingly
- When you click a food, it is destroyed and the score is updated in the top-left
- When you lose the game, a restart button appears that lets you play again
Languages available:
1. Exploratory Testing & Test Script vs. Carl!
Unlike the previous challenges, where we let you watch Carl work through the challenge and then you QA we want to flip the order. For this round, before watching the video:
- Open the starter file, and conduct your own exploratory testing.
- From your notes, create a test script. We highly recommend you then run your test script through the starter file and adjust as necessary.
- Then, watch the video and compare your test script to what Carl uncovers are the problems in this challenge. Are you as good as Carl?!?!
2. Overview
CWC_U5.C5
- Open your Prototype 5 project
- Download the "Challenge 5 Starter Files" from the Tutorial Materials section, then double-click on it to Import
- In the Project Window > Assets > Challenge 5 > Instructions folder, use the "Challenge 5 - Outcome” video as a guide to complete the challenge
3. The difficulty buttons look messy
- Center the text on the buttons horizontally and vertically
Hint: If you expand one of the button objects in the hierarchy, you’ll see a “Text” object inside - you have to edit the properties of that “Text” object
4. The food is being destroyed too soon
- The food should only be destroyed when the player clicks on it, not when the mouse touches it
Hint: OnMouseEnter() detects when the mouse enters an object’s collider - OnMouseDown() detects when the mouse clicks on an object’s collider
5. The Score is being replaced by the word “score”
- It should always say,
“Score: __“ with the value displayed after “Score:”
Hint: When you set the score text, you have to add (concatenate) the word “Score: “ and the actual score value
6. When you lose, there’s no way to Restart
- Make the Restart button appear on the game over screen
Hint: In the GameOver() method, make sure the restart button is being reactivated
7. The difficulty buttons don’t change the difficulty
- The spawnRate is always way too fast. When you click Easy, the spawnRate should be slower - if you click Hard, the spawnRate should be faster.
Hint: There is no information (or parameter) being passed from the buttons’ script to the Game Manager’s script - you need to implement a difficulty parameter
8. Bonus: The game can go on forever
- Add a “Time: __” display that counts down from 60 in whole numbers (i.e. 59, 58, 57, etc) and triggers the game over sequence when it reaches 0.
Hint: Google, “Unity Count down timer C#”. It will involve subtracting “Time.deltaTime” and using the Mathf.Round() method to display only whole numbers.