Unity Basics 2. Unity's building blocks

2. Unity’s building blocks

Building Blocks

  • Unity games consist of Scenes
  • Scenes consist of GameObjects
  • GameObjects consist of Components

Scenes

  • Manual: Scenes
  • Scene is a container for content
    • A game can be just one scene, or a combination of multiple ones
  • Example scenes:
    • Main Menu
    • Level
    • Game Over
  • Create New Scene: Assets > Create > Scene
  • New scenes use Unity’s default Scene template, but you can create your own

GameObjects

  • Manual: GameObjects
  • Pretty much everything in Unity is a GameObject
  • Fundamental objects in Unity that represent characters, props and scenery
  • Some examples…

GameObject Hierarchy

bg right:40% height:35%

  • GameObjects can have multiple child GameObjects $\Rightarrow$ they become parents
  • Children inherit their parent’s…
    • position
    • rotation
    • scale
    • activeness
  • Manual: Hierarchy: Parenting
  • Manual: Transform: Parenting
  • Note: Rotating child GameObjects can have wonky results if parent has any other scale than $(1,1,1)$.

Components

  • Manual: Components
  • GameObjects act as containers for Components that implement various functionalities
  • GameObject’s components and their settings are listed in the Inspector window

Some important components

Spatial information

  • Transform
    • Manual: Transform
    • position, rotation, scale
    • parenting information
    • included in every GameObject

Interacting with other GameObjects

  • RigidBody
    • Manual: RigidBody
    • for interacting with the physics engine
    • can receive forces and torque
  • Collider
    • Manual: BoxCollider
    • enables collision with other GameObjects
    • there are different shapes and sizes
      • CapsuleCollider(2D), BoxCollider(2D), PolygonCollider2D…
    • isTrigger
      • ✅ -> Collider is ignored by the physics engine, but can trigger events

Drawing the GameObject

  • MeshFilter
    • The mesh, or the 3d geometry of a GameObject
  • Renderer
    • Manual: MeshRenderer
    • The component for drawing the GameObject on screen
    • MeshRenderer, SpriteRenderer, LineRenderer, TrailRenderer…
  • Material

Custom Functionality