Check out a free preview of the full Game Development with Unity for Web Developers course

The "Setup Scene Game Objects" Lesson is part of the full, Game Development with Unity for Web Developers course featured in this preview video. Here's what you'd learn in this lesson:

Nick walks through setting up the initial in-game objects, including changing the camera view, adding new objects, editing an object's location, and scaling objects. Students' questions regarding if meters are the only unit of measurement used, if there is a common object naming convention, and if game objects are classes are also covered in this segment.

Preview
Close

Transcript from the "Setup Scene Game Objects" Lesson

[00:00:00]
>> So, next we need to actually set up things in our Scene. So we're going to use simple primitives, just a cube and a couple of spheres to represent all the things in our game world. And I have some specific values that we want to use to actually position those things in the world.

[00:00:22]
And I have them listed out here in the slides just as reference but, I'm going to switch over to Unity and actually add these things now. So, something I wanted to point out just really quickly in the Scene view is that if your scene looks a little bit different than mine, I have this Skybox here that's kind of a studio environment and that will be reflected on to game objects in the Scene.

[00:00:48]
If you don't have that, that's totally okay. It's still there in the project but you can toggle the visibility of that, you can toggle the Skybox fog and various other effects with this button in the upper right of the Scene view. So it looks like a little stack with a little star on top of it, and if you click that you'll get more of a grey default environment that you might expect.

[00:01:14]
And one other really important thing that I want to point out is that, if your hierarchy looks completely different and you don't have some of these gizmos in the Scene, it might be because you have a different Scene opened. It's very important to go to your project window, assets, Scenes, and make sure that you double click this main Scene and that's what you have open because that's where we're going to be working.

[00:01:39]
So I'm going to create that cube for our game board, and to do that, I'm going to come to the upper left of the hierarchy here and click this plus button, and that will open what's called the Create menu. And there's a lot of things in Unity that we can create.

[00:01:56]
We can create empty game objects, empty child game objects, and we can also create 3D objects, like cubes and spheres and other primitive 3D objects. So, I'm going to choose cube here. And when you create a new game object, it will give you the opportunity to rename it.

[00:02:19]
So, I'm going to change this to board because this cube is going to be kind of like a coffee table game board in our world. And with the board selected, you'll notice over in the inspector that there are several components that are already added to this game object.

[00:02:42]
Every game object has a transform component by default, so if I select some of these other game objects like the main camera or the directional light, you'll see that they also have a transform component that places them in the 3D world. And if I go back to the board, you'll see that it is at the origin of the world.

[00:03:05]
So, it is at position 0, rotation 0 and scale 0. There's a couple of different ways we can move it around. So again, if I hold down Option on Mac or Alt on Windows, I can actually orbit the camera here and take a look around this game object.

[00:03:23]
And if I want to frame it up, I can hit the F button just to get closer in or I can use the mouse scroll wheel to kind of go in and out. To manipulate this game object, there's a couple of different tools here in this panel. So I can use the transform tool or sorry, the move tool here, to move this around, I can click and drag on these arrows and I can move it up and down in the y.

[00:03:50]
And you'll see as I'm doing that, it updates the inspector on the right side, so the y value is updating as I'm doing that. I can also click between the arrows in the move tool to lock it to a plane. So if I just want to move this cube along the x, z plane, I can do that.

[00:04:09]
And then of course, there's also the Rotate tool, so that will adjust the rotation. If I just kind of click and drag in the middle of that, I can rotate this cube freely. But I'm going to hit Command Z on Mac or Ctrl Z on Windows to undo some of those, because we're actually just going to type in values for this directly.

[00:04:33]
So, the position for the x and z will remain at 0, but for y, we want to place this cube at 0.5. So it's a little bit off the ground, and if I rotate you'll actually see that it is now planar to the grid because every cube in Unity by default, has a size of 1 cubed.

[00:04:58]
And one is, well, the default unit in Unity is meters, and so this cube has a volume or, area of 1 meter cube. So, this cube is at 0.5. So because it's one unit tall, it's half off the ground and that's why it's now planar to the ground.

[00:05:26]
We're gonna create a couple of spheres now, to represent the player, the opponent and the collectible. And to do that, again we'll go to the create menu and the hierarchy here. I'll select the 3D object and choose sphere. And this one, I will call player. And this sphere, if you look at it is way too large for our game board here.

[00:06:00]
So you can also pan around by holding down Option and Command on Mac to kind of just pan there. But this is way too large for our game board, so we need to adjust the scale of this. So the scale for the player sphere will be 0.1. And we want to adjust that on the x, y, and z.

[00:06:29]
So 0.1 for the scale, and then the position, we're going to put this at an x of -0.3, y is 1.75, and then the z can be 0. So, this is going to place this, so that it's going to actually drop into the game board. These gizmos are a little big, these gizmo icons are a little bit large.

[00:07:00]
To adjust that, you can well either toggle the visibility of them or you can select this menu and I'm going to uncheck 3D icons. So if those are a little bit large in your Scene view, you can do that in this upper right menu here. So yeah, I've got this sphere here and that's going to drop into the world when the game starts.

[00:07:25]
Now, we also need a collectible, and that will be the little purple sphere that each player is trying to collect. So I will create a new 3D object, a new sphere here, and we'll call this collectible. And we'll position this at an x of 0, a y of 1.05, and as z of 0.

[00:07:58]
And then again, this is way too large, we want it to actually be even smaller than the player. So we are going to see scale this down to 0.025 for each one of the axis, okay? So 0.025 for all three. So now, it's pretty tiny in the Scene view but if I hit F, it'll frame it up and there's our tiny little sphere that will be the collectible in our game as the players are rolling around.

[00:08:36]
There's one more important thing we need to adjust on this collectible, so with it's still selected in the inspector, come down here to the sphere collider component and where it says is trigger, you want to check that to be true. Because we'll get into physics in a little bit, but we want this to be a trigger collider.

[00:08:57]
Yes, there's question.
>> Are meters the only unit of measure in Unity?
>> That's a good question. I'm not sure, I don't know that you can change it. I also don't think you would want to, well I take that back, I'm sure there's lots of scientific or archivist applications where you probably wanna change that, I don't know, I've never tried.

[00:09:21]
Yeah.
>> Is there a common naming convention for organizing these-
>> Game objects?
>> Yeah.
>> No. [LAUGH] No there's not a common naming convention. I would say the naming convention comes from video games really, like a collectible in a game as a collectible in Unity, so that's what we're calling it.

[00:09:46]
>> But like you put spaces and things you don't do CamelCase that kind of thing.
>> Gotcha, yeah, I generally put spaces like main camera and directional light here. But there really is no convention. I've seen plenty of projects with things all lowercase, underscores, I mean.
>> Nope, it's kinda wild.

[00:10:07]
It's really up to the developer.
>> Are the game objects classes?
>> No, so well they, I mean, yes and no. [LAUGH] It's kinda complicated. So, a game object is a class in Unity. So I guess yes, is the answer, but in this context, that's not really how I think of them.

[00:10:38]
I mean, they are instantiated in the Scene, and they do have a class you can access. So yeah, I don't know how to answer that, I guess. [LAUGH] But yeah, game objects are a class and they are instantiate in the Scene, so. Again I think the more important thing to pay attention to is that every game object has a transform.

[00:11:04]
So, let's see there any other questions? No, cool. Okay, so the last thing we were doing is we made sure that this collectible and its sphere collider is set to be a trigger. So, we'll talk more about physics later on but we're setting this to be a trigger collider rather than just a normal collider because we don't want the collectible to actually bump into things and intersect other objects.

[00:11:43]
We want the players to be able to roll right through and when it intersects, actually just collect that and execute some code that we'll write later. So it's not a physical thing that's being knocked around. So, if that were unchecked, it would be, and in the case of the player, it is unchecked.

[00:12:07]
We want the player to actually bump into the opponent, bump into the game board, that kinda thing. So, the collectible is a trigger. Very important to check that little checkbox or it's gonna be very confusing later on. [LAUGH] Okay, there's a few other things in the Scene like I mentioned.

[00:12:28]
We've got the main camera, we've got the directional light, those I've already set to the positions and values that they should be in in the startup project. But the cool thing about this is that now, if you go to the game view, you'll actually see something, the camera is set up so that it is framing this board that we placed in a very specific position.

[00:12:52]
You can see the little collectible there, you can see the lighting being cast onto these objects.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now