Module 1: Game Engine + Objects¶
Coverage¶
Git and GitHub¶
- Branches and Forks
- Learn how to manage branches and forks effectively.
- To save a Unity project, you only need the following three folders:
- Assets
- Packages
- ProjectSettings (These store project settings and are optional; you mainly need the Assets folder.)
- Do not push or submit the following folders as they can be re-generated by the Unity Editor:
Library
,Temp
,Logs
,obj
,.vs
.
Basic Unity Skills¶
- Open and work with the Unity Editor.
- Configure a 2D camera, including setting the world size.
- Build your game for:
- EXE format.
- WebGL.
- Host WebGL builds for public access.
User Interaction¶
- Implement keyboard state polling for user input.
Unity Objects¶
- Work with textures and create 2D sprite objects.
- Attach scripts (MonoBehaviour components) to GameObjects.
- Assign GameObjects to script variables in the Unity Editor.
- Use the Transform component to modify object positions.
Unity Setup¶
Unity Installation¶
- Download and install Unity 3D. Refer to Unity Installation Help.
- Stick to the specified Unity version for the class; do not update versions during the course as this may cause project delays.
Online Tools¶
- Hosting a WebGL Build
- Use GitHub Pages: https://pages.github.com/
Working with Git and GitHub¶
- Fork the provided repository to track changes.
- Clone the forked repository to your local machine.
- Navigate to the Unity project folder (
1.BasicSimpleProject
) and note:- Assets folder: Store all project resources here.
- EXE folder: Contains build results (not for editing).
Folder Management¶
- Before submission:
- Remove unnecessary folders:
Temp
,Obj
,Library
,Logs
,Builds
. - Keep backup copies of your work to prevent accidental loss.
- Remove unnecessary folders:
Observations in Unity Editor¶
- When opening a project in Unity, folders such as
Library
,Logs
,Temp
are auto-generated. These improve startup performance but are not needed for saving or sharing your project.
Module 1: Examples and Exercises¶
Example 1: Basic Simple Project¶
Exploring the Scene¶
- Open the ClassExample scene:
- Navigate to the Project panel:
Assets
→Scenes
→ClassExample
. - Ensure you are in 2D mode by selecting the 2D option in the top-left corner of the Scene window.
- Navigate to the Project panel:
Key Editor Windows¶
- Scene: Interactive editor for designing levels.
- Hierarchy: Lists all objects in the scene.
- Inspector: Displays details of the selected object.
- Game: Preview what the player will see.
- Console: Displays error and status messages.
Camera Configuration¶
- Initial Settings:
- Position:
(0, 0, -10)
- Rotation:
(0, 0, 0)
- Projection: Orthographic
- Size:
100
(half the vertical height of the visible world). - Clipping Planes: Near:
0.3
, Far:1000
.
- Position:
Textures and Sprite Objects¶
- Drag images into the Assets folder to import textures.
- Ensure the Texture Type is set to Sprite (2D and UI).
- Create a 2D Sprite Object:
GameObject
→2D Object
→Sprite
.- Assign a texture to the SpriteRenderer component.
World Coordinates¶
- The visible height and width of the world are determined by the camera's size and aspect ratio.
Example 2: Scripts and Keyboard Input¶
Adding Scripts¶
- Add a script to a GameObject:
- Use the Add Component button in the Inspector.
- Drag a script file onto the Inspector window.
Programming Model¶
- Unity follows the Entity-Component-System (ECS) architecture:
- Entity: GameObject.
- Component: Components like Camera, SpriteRenderer, or custom scripts.
- System: Unity's execution protocol (e.g., calling
Awake()
,Start()
,Update()
).
Script Lifecycle¶
- Awake(): Called first for initialization.
- Start(): Called once after
Awake()
. - Update(): Called once per frame during gameplay.
Key Learnings¶
- Open a Unity Scene and configure 2D camera settings.
- Create and manipulate 2D sprite objects.
- Add and manage scripts in Unity using the ECS architecture.
- Distinguish between Editor Mode and Play Mode:
- Changes made in Play Mode are not saved after exiting.
Final Notes¶
Debugging¶
- Refer to the Debugging Guide.
Building Your Game¶
Self-Practice¶
- Follow the instructions provided and practice in class.
- After each step, compare with the instructor's demonstration.
Credits¶
All clipart used in this class are from the "Microsoft Office Free Clip Art Library."