Chapter 6: Component, The Verb

By | March 25, 2019

Chapter 6: Component, The Verb

 

In this chapter we're going to look at the also all-important Component. We'll learn that they are the verbs that make GameObjects go. We'll make one such GameObject, a Sphere, do just that. We'll learn about Parameters and how they can be used to make things go better.

 

Fig 6.1 shows the Component drop-down menu's alternate access in the Inspector View.

 

Components

Up next is our Component drop-down menu. Components can be chosen from here. The alternate method of access is to select a GameObject and then click Add Component in the Inspector. This is the most convenient and useful way of adding Components; the dialogue adds search functionality. Using either method elicits a long list of options, each with a sub-menu. Many of the sub-menus are themselves a long list of options. Much of the time the Components' functionality is described by its name in such a way as to make its purpose self-evident. If you need to add a particular bit of functionality to your game, search the Components in the Inspector; more often than not you'll find what you're looking for. Consequently, it is not important to memorise each of these elements and all of their respective functionalities. It is important, however, to understand Components conceptually. If GameObjects are nouns, Components are verbs. They give GameObjects functionality, allowing them to act. As verbs, unlike their noun counterparts, Components don't have a physical analog. Components are scripts, mini programs, that exist as attachments to GameObjects. With a GameObject selected, its Components will be visible in the Inspector View. In fact, this is the primary use of the Inspector View: to add, subtract, adjust, and otherwise inspect the Components attached to a GameObject. Let's do that now.

 

  • Open Scene sec1Chap6Component

  • Select Main Camera and from the GameObject menu, select Align View to Selected if necessary

    Fig 6.2 shows the Main Toolbar with the cursor over the Play button

  • On the Main Toolbar press Play

     

What happened? The Scene View was toggled with the Game View and the rest of Unity was tinted red (if it wasn't, go to Edit>Preferences>Colors and specify Playmode tint as red as advised previously). You are no longer viewing your game as a developer, but as a player. Game View displays how your Scene (level) will look and behave when played. But what happened to the Sphere? Nothing. The Sphere currently has only four Components, none of which provide any real functionality other than the functionality to be seen (Mesh Renderer). While Scenes comes with gravity by default, the Sphere actually lacks the ability to be affected by gravity! Let's change that.

 

  • On the Main Toolbar press Play to exit Game View

  • With the Sphere selected, click Add Component in the Inspector View

  • Select Physics>Rigidbody

  • On the Main Toolbar press Play

 

Now the Sphere falls! It falls unsatisfactorily however. Fortunately Components often have many parameters that can be modified. Parameters are values that help inform Scripts' behavior. They are assigned before the game runs and remain unchanged as the software executes. Let's modify a parameter to make the Sphere's physics more satisfying.

 

  • On the Main Toolbar press Play to exit Play Mode

  • Select Assets>Import Package>Physics Materials and choose to Import

  • Select the Sphere and in the Inspector View locate the Sphere Collider Component

  • To the left of the Material parameter field None (Physic Material) click the target icon

    Fig 6.3 shows the Target icon being selected and the Select PhysicMaterial dialogue

  • In the Select PhysicMaterial window, choose Bouncy

  • On the Main Toolbar press Play

 

You may have expected the Sphere to bounce, which it did. What should have been unexpected however, is that it continued to bounce higher and higher! You can address this by modifying yet another Parameter, Drag, in the Rigidbody component.

 

GameObjects are inanimate. In order to do anything, including something so simple as to be seen or to be affected by gravity, they need Components. Components can be fine tuned through their parameters.

 

As mentioned, most Components' functions are described by their names. Components are all well documented (their documentation can be easily obtained by clicking the Help icon towards the upper right hand corner of the added Component's panel in the Inspector). For these reasons it would be folly to describe all the Components that come with Unity. Do be aware, however, of the most commonly added Components' respective headings;

 

  • Character Controller (Standard Package)

  • Physics

  • Audio

  • Miscellaneous

  • UI

 

Pre-made Physic Materials are now part of the Characters' package.

 

In this lesson we learned about Components and Parameters and put both to use in order to simulate a bouncing ball. We learned that Components are Scripts (code) that you attach to GameObjects in the Inspector View. We looked at some of the more useful and therefore more common Component types. In the next chapter, we'll visit the Playmaker drop-down menu.

No-Code Video Game Development With Unity3D and Playmaker  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ 03/26/19

Michael Kelley  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ page 2 of 4

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.