Game Development Reference
In-Depth Information
Components
Now that you've been introduced to the Transform component, let's look at a few more components.
Components are the building blocks that specify the functionality for every gameObject. In addition
to the mandatory Transform component, each of the primitive objects you created has a Mesh
Renderer, something called a Collider of an appropriate shape for its primitive, and a Mesh Filter for
its particular primitive's geometry. When you create a Unity gameObject from Create Other, it comes
complete with the components that make it what it is.
Mesh Renderer
Let's begin with the Mesh Renderer component (Figure 2-13 ). This component is what causes the
object (whose mesh is found in the Mesh Filter component) to be “rendered” or drawn into the Scene
view. Its first two parameters dictate whether it can cast or receive shadows (providing there is a
light in the scene set to cast shadows). It also holds an array for the material or materials assigned
to the mesh. For the test objects, each has only one material, so the Material array Size is 1 and that
material resides in the Element 0 slot. Arrays always start counting at 0, not 1.The material, in this
case, Default-Diffuse is shown at the bottom of the Inspector, along with a preview of the material.
Because this is an internally generated material, you may not adjust it. Materials dictate the visual
aspect of the object's surface qualities.
Figure 2-13. The Mesh Renderer component
Select each of the cubes, and
disable their Mesh Renderer components by
unchecking the check box to the left of the component name.
Colliders
As each cube is selected and its Mesh Renderer disabled, you will see a green outline of the cube
remaining. This represents the cubes' Box Collider component. Collider components have two main
types of functionality. The default is to block physics-based objects from going through the volume
defined by the Collider component. The second, when the collider's Is Trigger parameter is checked,
is to allow objects to pass through the object but to register the event for further evaluation and
possible action. Any object that must cause an event to be triggered on pick, collision, intersection,
or ray-cast must have a collider of some type. Even with their Mesh Renderer turned off (invisible in
the scene), the objects are still fully active in the game.
 
Search WWH ::




Custom Search