Challenge 2 - Play a Game of Fetch

Tutorial

·

Beginner

·

+10XP

·

60 mins

·

(34)

Unity Technologies

Challenge 2 - Play a Game of Fetch


Challenge Overview:

Use your array and random number generation skills to program this challenge where balls are randomly falling from the sky and you have to send your dog out to catch them before they hit the ground. To complete this challenge, you will have to make sure your variables are assigned properly, your if-statements are programmed correctly, your collisions are being detected perfectly, and that objects are being generated randomly. Finally you will continue practicing your bug reporting skills.

Challenge Outcome:

  • A random ball (of 3) is generated at a random x position above the screen
  • When the user presses spacebar, a dog is spawned and runs to catch the ball
  • If the dog collides with the ball, the ball is destroyed
  • If the ball hits the ground, a “Game Over” debug message is displayed
  • The dogs and balls are removed from the scene when they leave the screen
  • A detailed bug report

Languages available:

1. Overview

CWC_U2.C2

  1. Open your Prototype 2 project
  2. Download the "Challenge 2 Starter Files" from the Tutorial Materials section, then double-click on it to Import
  3. In the Project Window > Assets > Challenge 2 > Instructions folder, use the "Challenge 2 - Instructions" and “Outcome” video as a guide to complete the challenge

2. Dogs are spawning at the top of the screen

  • Make the balls spawn from the top of the screen

Hint: Click on the Spawn Manager object and look at the “Ball Prefabs” array

3. The player is spawning green balls instead of dogs

  • Make the player spawn dogs

Hint: Click on the Player object and look at the “Dog Prefab” variable

4. The balls are destroyed if anywhere near the dog

  • The balls should only be destroyed when coming into direct contact with a dog

Hint: Check out the box collider on the dog prefab

5. Nothing is being destroyed off screen

  • Balls should be destroyed when they leave the bottom of the screen and dogs should be destroyed when they leave the bottom of the screen

Hint: In the DestroyOutOfBounds script, double-check the lowerLimit and bottomLimit variables, the greater than vs less than signs, and which position (x,y,z) is being tested

6. Only one type of ball is being spawned

  • Ball 1, 2, and 3 should be spawned randomly

Hint: In the SpawnRandomBall() method, you should declare a new random int index variable, then incorporate that variable into the the Instantiate call

7. Bonus: The spawn interval is always the same

  • Make the spawn interval a random value between 3 seconds and 5 seconds

Hint: Using "InvokeRepeating" won't work here because it requires you to define a constant repeat rate. Try using the simpler "Invoke" method instead, then re-setting the startDelay and re-calling the method from within the "SpawnRandomBall" method.

8. Bonus: The player can “spam” the spacebar key

  • Only allow the player to spawn a new dog after a certain amount of time has passed

Hint: Search for Time.time in the Unity Scripting API and look at the example. And don’t worry if you can’t figure it out - this is a very difficult challenge.

9. Continue to Create Bug reports

Using the bug report you created in the first challenge continue to populate it with bugs you find in this challenge - remembering to tag them, and prioritize them appropriately. Remember to try and find additional bugs that are not outlined in the challenge instructions.

Complete this tutorial