Assignment 8: Collection Game
Due Friday, November 1, before midnight
The goals for this assignment are:
-
Implement a simple collection mechanic
-
Implement a user interface
-
Implement a spawner
1. Getting Started
It is not necessary to fetch from the upstream repository this week. Instead,
-
Create a new scene, called
A08_Collection
, and save it to yourHelloUnity/Assets/Scenes
folder.
Scene and Player Setup
In your scene:
-
Initialize your scene with the prefab containing your level from assignment 7.
-
Add your character prefab from assignment 7.
2. Assignment Goals
In this assignment, you will implement a simple collection game mechanic using colliders. From assignment 7, you have already configured your player character and level with colliders. In this assignment, you will write a script that detects collisions between the player and special objects. When the player runs into a collectable object, the object should disappear, and the number of collected objects should increase on the game’s user interface.
2.1. Collection Game
Write a script, Scripts/CollectionGame.cs
, that will implement the mechanics for your mini-game.
Place your script on the player character. At minimum, your script should take the UI text
as a parameter.
Requirements:
-
Add a user interface
-
Detect collisions between the player and your collectable object. Use OnTriggerEnter to detect collisions with the player.
-
Use tags or a naming convention to distinguish your collectable object from other types of objects
-
Update the count on the user interface when the player picks up an object
-
Make the collectable object disappear when the player picks it up. You can use
GameObject.SetActive
to hide the object. -
Implement an effect, such as an animation, that shows that the object has been picked up. This should be implemented as an animation or script on the collectable object so it can be triggered from different scripts.
Resources:
2.2. Object Spawner
A spawner is a type of game object that generates other game objects. Spawners are used in particle systems and for generating enemies. In this assignment, we will use a spawner to generate collectable objects.
Write a script, Scripts/Spawner.cs
, to implements a spawner. This script should be a component on
an empty GameObject that can serve as a landmark for where objects will be spawned. For example,
we place the Spawner script on a sphere object so we can visualize the size of the spawning radius.
We can hide the sphere by unchecking its MeshRenderer
. You spawner should minimally support parameters to
specify the
-
template object (use a prefab for this),
-
range from the spawner center to create objects, and
-
max number of spawned objects.
Requirements:
-
Use
GameObject.Instantiate
to create duplicates of a prefab that corresponds to your collectable object -
Support the spawn parameters: template, range, and max number of spawns
-
Use the flag in GameObject, called
activeInHierarchy
, to determine whether a spawned object has been picked up. If it has been picked up, spawn the collectable elsewhere. -
Generate random positions for spawned objects that are within the given radius of the spawner. You can use
Random.RandRange
to generate random numbers for spawning. -
Your collectable object has a collider on it so it can be picked up. Use the bounding box on this collider (see Collider.Bounds) to position the collectable to it sits on top of the terrain.
-
(Optional - See assignment 9) Use a navigation mesh to ensure that the spawned objects spawn in areas that are accessible to the player
3. What to hand in
-
Your scenes with your level and player in it
-
Your scripts, ``
-
Updated README
-
A video or GIF showing the motion controller, intersections with the world, and collection mechanic
-
Credits/links for any assets that you did not make yourself — if you add assets this week.
-
Don’t forget to commit your changes and then push them to Github. Using Git Bash,
run the following command inside your HelloUnity
directory.
$ cd HelloUnity
$ git add .
$ git commit -m "Finished HelloUnity"
$ git push
Run git status
to check the result of the previous git command.
Check the Github website to make sure that your program uploaded correctly.
Assignment rubrics
Grades are out of 4 points.
-
Your scripts need to be feature complete (3.5 points)
-
Readme (0.5 point)
Submission rubrics
For full credit, your submission must
-
In your README, include videos or gifs showing your working scripts
-
Some credit lost for missing features or bugs, depending on severity of error
-
-100% for failure to commit work to Github
-
-100% for failure to build and run on the lab Windows machines