GameObjects and Components

From ETC Public Wiki
Jump to: navigation, search

Note: For additional resources, visit the following links:

Game Object Component Relationship:
Component Script Relationship:

  1. Every object in Unity starts as a GameObject. A GameObject is simply a container with a set of parameters that can be built upon using Components. A Component is a script that grants a function to the GameObject. To better understand the Component system let's start by creating a Camera object.
  2. To start creating our Camera we first must start by creating an empty GameObject. Do this by selecting the GameObject drop down in the tool bar and selecting "Create Empty". (See Figure 1)
    Fig. 1, Create Empty GameObject
  3. This will create a blank GameObject in our world. We can see this in the Scene View. (See Figure 2)
    Fig. 2, Empty GameObject
  4. While the Empty GameObject is selected we can see the details of the object in the Inspector Window. As we can see the only contents in the GameObject is the object name and Transform values. (See Figure 3)
    Fig. 3, Inspector View of Empty GameObject
  5. We then need to rename our Empty GameObject to Camera. That way when we see the object in the Hierarchy Window we will know the object's function. (See Figure 4)
    Fig. 4, Rename GameObject to "Camera"
  6. Now we have an Empty GameObject named Camera, now we need to start adding functionality to the GameObject to give it the functionality of a Camera. While the GameObject is selected Click the dropdown Component menu, expand the Rendering field and select "Camera". (See Figure 5)
    Fig. 5, Add Camera Component
  7. Now our object will function as a camera, as we can see in the Scene View as well as the Inspector (See Figures 6 and 7). We could further expand upon the Camera's functionailty by adding a Flare Layer so the camera can receive lens flares, a GUI Layer so we can add a GUI to it, an Audio Listener so the camera can receive sounds, and a Depth of Field Component to give us some extra control. To do this all we have to do is select the GameObject and add the respective component we want to add.
    Fig. 6, Camera Functionality Added
    Fig. 7, Camera Functionality Added