You are on page 1of 29

Unity Basic Concepts

GAME PROGRAMMING
C# PROGRAMMING AND UNITY

TRINH THI NGOC LINH

1
Scene
 Scenes are where you work with content in Unity
 They are assets that contain all or part of a game
 You can create any number of scenes in a project
 For example:
 You might build a simple game in a single scene
 With a more complex game, you might use one scene per level, each with its
own environments, characters, obstacles, decorations, and UI

2
Scene

3
Scene

4
Camera Component
• The devices that capture and display the world to the player
• By customizing and manipulating cameras, you can make the presentation of your
game truly unique
• You can have an unlimited number of cameras in a scene

5
Game Object
• Game Object is a fundamental building block and a core concept
representing any object that can be placed in a scene
• It is the base class for all entities that can exist in your game world,
including:
• Characters
• Items
• Obstacles
• Lights
• Cameras
• ...
6
Game Object
• Hierarchy Structure:
• Game Objects follow a hierarchical structure,
forming a tree-like representation called the
Hierarchy
• Each Game Object can have zero or more
child Game Objects, and each child can have
its own children, creating a parent-child
relationship
• This hierarchy allows you to organize your
scene and define how objects are positioned
relative to each other

7
Game Object
• A Game Object itself doesn't have
any visible or interactive properties
on its own. It is essentially an empty
container
• Game Objects serve as containers
for components that define their
functionality, appearance, and
behavior

8
Component
• Components are the functional pieces of every GameObject
• Components contain properties which you can edit to define the
behavior of a GameObject

9
Component
• Some common components include:
• Transform (position, rotation, and scale)
• Rigidbody (physics properties)
• Mesh Renderer (visual appearance)
• Collider (collision boundaries)
• Scripts
• Audio Source
• Particle System (Generates various visual
effects like smoke, fire, or explosions)

10
2D Sprite
• Sprites are simple 2D objects
that have graphical images
(called textures) on them
• Unity uses sprites by default
when the engine is in 2D
mode. When viewed in 3D
space, sprites will appear to
be paper-thin, because they
have no Z-width

11
3D Model
• In Unity, a 3D model refers to a three-dimensional
representation of an object or scene
• The 3D models can represent characters,
environments, props, and various other elements
in the game world
• These models are typically created using 3D
modeling software such as Blender, Autodesk
Maya, 3ds Max...Unity supports a variety of file
formats for importing 3D models, including FBX,
OBJ, and others...
• Once imported into Unity, 3D models can be
manipulated, animated, textured, and combined to
build the visual aspects of the game
12
Tag and Layer
• Tag
• A tag is a label or identifier that you can
assign to GameObjects to categorize and
differentiate them based on their
characteristics or purposes
• Tags are commonly used to group objects
together and provide an easy way to
reference and interact with them in scripts
and components
• For example:
• Tag: "Player"
• Tag: "Enemy"

13
Tag and Layer
• Layer
• A layer is a way to categorize and separate
GameObjects based on their interaction and
rendering properties
• Layers are particularly important for
controlling how objects interact with each
other in terms of physics and collision
detection, as well as how they are rendered
and affected by lighting

14
Tag and Layer
• Layer
• For example: In a top-down shooter game, you may want to create a layer for
enemies to control how they interact with the player and other objects:
• Layer: Player
• Layer: Enemy
• Layer: Obstacle
• For example: In an open-world game, you might have multiple cameras
showing different areas of the game world. To optimize performance, you can
control which objects are visible to each camera using layers:
• Layer: Player
• Layer: Environment
• Layer: UI

15
Prefab
• Prefab (short for "prefabricated") is a
special type of asset used to store and
manage reusable GameObjects with
components and settings
• Prefabs act as templates for creating
instances of GameObjects in your
scenes. They allow you to define a set
of properties, components, and child
GameObjects that you can reuse
throughout your game project

16
Tilemap
• A 2D grid-based system used to create 2D levels and environments
• It allows developers to create levels by placing and arranging tiles in a
grid, providing a straightforward way to design and manage 2D game
worlds

17
Tile Palette
• A tool that simplifies the process of working with Tilemaps
• It provides a user interface where you can create and manage
collections of tiles, making it easier to draw and paint the level in the
Scene view

https://www.youtube.com/watch?v=DTp5zi8_u1U&list=PLJBcv
4t1EiSysOLQnh2AwqmD9QTg9Qlx-&index=1

18
Practice
In order to understand the moving of GameObject’s transform, use Unity 2D for this
practice to create a scene and Player GameObject.
The exercise will take 20 minutes, and students need to familiarize themselves with
operations in the scene windows, using tools such as move, rotate, scale, zoom in,
and zoom out.

Proficiency in navigating the scene


window is crucial when working on a
game project. Necessary components
such as tiles, sprites, game objects, etc.,
have already been created; students
only need to download and import them
into the project.
19
Practice 1 – GameObject
 Create a new Unity 2D project
 Download the asset files. Drag and drop all folders to the Asset folder of the Unity
2D project

20
Practice 1 – GameObject
 Create new Scene
 In the Project window, navigate to Assets > Prefabs > 1.2_Basic-Game-Object
 Drag and drop ./Assets/Prefabs/Tilemap Grid.prefab into the Hierarchy
window or the Scene window
 Note: Remember to select Reset Transform each time you add a GameObject
to the Scene

21
Practice 1 – GameObject
 Unity 2D layer setting
1. Select Background Tilemap, on inspector window, click Layer > Add Layer
2. In the sorting layer section, click the + button and add 3 layers: Background,
Platform, Player. Arrange them in the order of their intended display
3. In component Tilemap Renderer - Additional Settings, set Sorting Layer to
Background

22
Practice 1 – GameObject
 GameObject
1. Perform the aforementioned step 3 for the remaining GameObjects within the
Tilemap Grid with the Sorting Layer set to Platforms
2. Add the Exit GameObject to the scene, adjust its Transform if necessary, and set
the Sorting Layer to Platform
3. Add the Ginger (Player) GameObject to the scene, adjust its Transform if
needed, and set the Sorting Layer to Player
4. Finally, delete the default Main Camera in the scene and add Cameras by
dragging and dropping it from the Prefabs folder

23
Practice 1 – GameObject
Press Play button (Ctrl + P) to test the new scene.

24
Practice 2 – Sprites, Tilemap
A. Practice with Slicing Sprite
1. Select all sprite assets set:
 Pixel per Units: 32 and apply

2. Select SPA_Rock_Grass_Water asset,


set:
• Sprite mode: Multiples and apply
3. Select SPA_Rock_Grass_Water asset,
click Spirte Editor and set:
• Slice type: Automatic and apply

Repeat steps 2 and 3 for SPA_Background brown tint

25
Practice 2 – Sprites, Tilemap
A. Practice with Slicing Sprite
Slice SPA_Player_Ginger
1. Select SPA_Player_Ginger asset, set:
 Sprite mode: Multiples and apply

2. Click Spirte Editor and set:


 Slice type: Grid By Cell Size

3. Set params:
 Pixel size: X: 32; Y: 32

 Offset: X: 0; Y: 0

 Padding: X:6; Y: 6

 Click Slice and Apply

Repeat steps 1,2 and 3 for ‘SPA_Background brown tint’


26
Practice 2 – Sprites, Tilemap
A. Practice with Slicing Sprite
Slice SPA_Player_Ginger
1. Select SPA_Player_Ginger asset, set:
 Sprite mode: Multiples and apply

2. Click Spirte Editor and set:


 Slice type: Grid By Cell Size

3. Set params:
 Pixel size: X: 32; Y: 32

 Offset: X: 10; Y: 4

 Padding: X:6; Y: 6

 Click Slice and Apply

27
Practice 2 – Sprites, Tilemap
B. Create Tilemap
1.Drag and drop ‘Tiles’ folder to Asset folder of Unity 2D project
2.Select GameObject > 2D Object > TileMap > Rectangular. Rename to
‘Platforms Tilemap’
3.Open Tile Palette by select Window > 2D > Tile Palette.

28
Practice 2 – Sprites, Tilemap
B. Create Tilemap
Because we imported the ‘Tiles’ folder. 'Platforms Tilemap' will already be present in
the tile palette.
Select the edit mode and use the Tile Palette toolbar to draw tiles onto the scene.

29

You might also like