GameObjects and Components
Note: For additional resources, visit the following links:
Game Object Component Relationship: http://unity3d.com/support/documentation/Manual/The%20GameObject-Component%20Relationship.html
Component Script Relationship: http://unity3d.com/support/documentation/Manual/The%20Component-Script%20Relationship.html
- 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.
- 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)
- This will create a blank GameObject in our world. We can see this in the Scene View. (See Figure 2)
- 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)
- 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)
- 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)
- 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.