Join Adam Crespi for an in-depth discussion in this video Creating GameObjects, part of Unity 4.3 Essential Training.
- View Offline
In making games beyond simply bringing in assets we need to add interactivity and really make this a place we can run around in. Do things in, not just run around. So far we've brought in our gallery, got the materials on, at least got a working light, and got most of the lake and terrain around. Still needs the water, but that'll come in a bit. The big deal, though, is we need to start getting the collision and interactivity in place. We need to make game objects. Right now, these are all actually game objects.
Anything that we can select here in the hierarchy. Is a game object, and something that can be called directly in a script, and affected in some way. Picking, for example, the cam light surface mount, shows in the inspector that this has a name. And we may want to put on a number. We can tag it, and put on a layer. And it is a model, and what are the model's properties? Well, it's here it's got an animator controller on it. Its got a mesh render so it does show up. It's got materials and we can even get into casting and receiving shadows and so forth.
This is already a game object, but there's a few other game object types we may want to use as part of making our game and adding on the interactivity. Under game object, we can create an empty game object. And this is equivalent in 3DS Max or Maya to a dummy or a null. What this means is that it's a named object with its own transform. That actually doesn't have a mesh render of its own. I'll make one and explore its properties and how we can use it. I've made my game object and it really just appears in the center of the view.
We can see it by it's transform. And it's name Game Object. Right now it actually doesn't have anything on it. It simply exists as another point in space. If you've done some rigging perhaps in 3DS Max or Maya, the idea of an extra transform should be a familiar one. A lot of times we use this as a reference. Calculate the distance between two game objects and look between them for example. We might see that in a script where we're saying, tell the player or something else to look between and interpolate.
What we'll do with this game object is start to parent things under it. This way, when we have the whole place sync out of sight through the lake, we can move one object instead of trying to move everything all at once. I'm going to rename this game object over to master building. And now I'll take my other pieces and drop them onto it here in the hierarchy. I'll take the gallery, the can light surface mount, hold and control to select multiples. And that should be it for the moment I think, but I can always add more.
I'll drag them under master building. Unity shows for me a blue oval which denotes, yes it's going to parent under there. When I let go, everything is parented under master building. And opening that up shows those objects. For example, if I pick the cam light, press ctrl+d to duplicate it and clone it, that parenting relationship is maintained. So when we start to populate this building through with art and walls and so forth, we'll make sure it's patented under master building. In the end, we'll pick master building.
Focus out on everything in here and we'll take master building and drop it under the lake. This way, when the player steps out or collides outside of the building with a trigger, this animation is activated and the building will disappear. I'll press Undo before I sink my building too far below the lake bed. A Game Object then, is a very valuable component, even though, itself, it may not have anything in it. Now, if you'd like to be able to see these Game Objects, you can add a tag on.
Right up here in the Inspector, next to the visibility check box and the name, is a cube. I'll click that cube and select an icon for the Game Object. In this case, I'm going to make the master here, yellow. And now master building is visible wherever I go in the seen view. Anywhere that I pan around, that tag will show. And I can center it if I'd like on the buildings. This is a handy technique because now I've got full control of everything in here by one object, at least to move it around. The other Game Objects we'll end up using, some of which we've already seen, are under Create Other.
The idea then, is that these are native objects in Unity versus imported objects. But really, anything in the scene is a Game Object. We'll start to put in other pieces, such as particle systems and other lights. We may make a few more primitives, and we'll also see things like an audio reverb zone. Defining in here, where does the audio sit in a particular location? Maybe a hiss or a hum as we pass by the air conditioning. So let's get started adding some collision and interactivity into this space. Transforming it from simply a place to run around to a place to play in and bring our game mechanic to life.
- Designing the game
- Creating and transforming objects
- Importing and configuring models and textures
- Setting properties in the Inspector
- Creating the terrain geometry
- Building materials and adding shaders
- Creating GameObjects
- Exploring physics
- Animating objects
- Lighting the scene
- Creating 2D game elements
- Adding special effects