Unity Lab #3: GameObject Instances

C# is an object-oriented language, and since these Head First C# Unity Labs are all about getting practice writing C# code, it makes sense that these labs will focus on creating objects.

You’ve been creating objects in C# since you learned about the new keyword in Chapter 3. In this Unity Lab you’ll create instances of a Unity GameObject and use them in a complete, working game. This is a great jumping-off point for writing Unity games in C#.

The goal of the next two Unity Labs is to create a simple game using the familiar billiard ball from the last lab. In this lab, you’ll build on what you learned about C# objects and instances to start building the game. You’ll use a prefab—Unity’s tool for creating instances of GameObjects—to create lots of instances of a GameObject, and you’ll use scripts to make your GameObjects fly around your game’s 3D space.

Let’s build a game in Unity!

Unity is all about building games. So in the next two Unity Labs, you’ll use what you’ve learned about C# to build a simple game. Here’s the game that you’re going to create:

Images
Note

When you start the game, the scene slowly fills up with billiard balls. The player needs to keep clicking them to make them disappear. Once there are 15 balls in the scene, the game is over.

So let’s get started. The first thing you’ll do is get your Unity project set up. This time we’ll ...

Get Head First C#, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.