Week 3 | Session 2 - Launch a Projectile Prefab - April 7, 2020
Tutorial
·
Beginner
·
+10XP
·
60 mins
·
(45)
Unity Technologies

In this live session, you will allow the player to launch the projectile through the scene. First you will write a new script to send the projectile forwards. Next you will store the projectile along with all of its scripts and properties using an important new concept in Unity called Prefabs. The player will be able to launch the projectile prefab with a tap of the spacebar. Finally, you will add boundaries to the scene, removing any objects that leave the screen.
1. Overview
This is the same content covered in Lesson 2.2 in the independent Create with Code Course.
What you will make:
- The player will be able to press the Spacebar and launch a projectile prefab into the scene, which destroys itself when it leaves the game’s boundaries. The animals will also be removed from the scene when they leave the game boundaries.
What you will learn:
- Transform a game object into a prefab that can be used as a template
- Instantiate Prefabs to spawn them into the scene
- Override Prefabs to update and save their characteristics
- Get user input with GetKey and KeyCode to test for specific keyboard presses
- Apply components to multiple objects at once to work as efficiently as possible
2. Before you Begin
To participate in this session and follow along, you need:
- Unity 2018.4 installed
- An up-to-date project open in Unity:
- If you have followed along with us this week and have your own project ready, you are good to go!
- You can also download the instructor's up-to-date project and import it (If you don't know how to import a project, you can read how here)
If this is your first Create with Code live learning session, you can catch up by:
- Following along with the recordings of our previous live learning sessions
- Completing the same lessons in the independent Create with Code Course
*Note - it is not necessary for you to catch up, but it is recommended for an ideal learning experience.
3. Recorded Live Session - 7th April - 9am PST
If you missed this live session, you can catch up with the video below:
4. Recorded Live Session - 7th April - 5pm PST
If you missed this live session, you can catch up with the video below:
5. Next Steps
Get caught up:
If you were not able to finish the session along with the instructors, you can catch up by:
- Re-watching this recorded session when it is posted in Step 3 above at 3am PT (10am UCT) the morning after this session's date
- Picking up where you left off in Lesson 2.2 of the independent Create with Code Course
Optional homework:
- Create a new projectile prefab and give the player the option to launch different projectiles with different keys
Extra credit:
If you want to go ahead and preview what we'll be covering in the next session, you can give it a try in Lesson 2.3 of the independent Create with Code Course.