Game Development Reference
In-Depth Information
The GameObject
The
GameObject
is, in many senses, the fundamental unit or entity inside a scene.
It corresponds most naturally to what we'd call a
thing
in the everyday sense.
It doesn't really matter what kind of context-specific behaviors or things you'll
actually need inside your own games, because in all cases, you'll need
GameObjects
to implement them.
GameObjects
don't need to be visible to the gamer; they can be,
and often are, invisible. Sounds, colliders, and manager classes are some examples
of invisible
GameObjects
. On the other hand, many
GameObjects
will be visible:
meshes, animated meshes, sprites, and so on. In all cases, however, whether visible
or invisible, the
GameObject
is instantiated inside a scene as a collection of related
components. A
component
is essentially a class derived from
MonoBehaviour
,
and it can be attached to a
GameObject
in the scene to change its behavior. Every
GameObject
has at least one minimal component in common, and it's impossible
to remove it, namely, the
Transform
component (or the RectTransform for GUI
objects). This component keeps track of an object's position, rotation, and scale.
For example, if you create a blank, empty game object in the scene by going to
GameObject
|
Create Empty
from the application menu, as shown in the following
screenshot, you would end up with a new game object in the scene, featuring only
a Transform component. Thus, even a new and empty
GameObject
is not, strictly
speaking, empty, but it's as empty as a
GameObject
ever gets. The object still needs a
Transform component to maintain its physical location in a scene.
All GameObjects feature a Transform component