Reported by Josh Manto, DKU Undergraduate Class of 2024
On the second of June 2022, the HRC Anthropocene Lab hosted a workshop on Unity Game Engine, a development platform often used for application, website, and game development. The workshop was facilitated by Leiyuan Tian and was taught by Tony Ren, both of whom are from the class of 23’. From covering basic interface navigation, understanding hierarchies, to more in-depth concepts like game physics and scripting, Tony and Leiyuan were successful in providing a beginner-friendly tutorial to Unity game engine.
Tony showing us the the preliminaries, which include downloading Unity Game Engine, and an IDE (integrated development environment) such as Visual Studio Code to write scripts. After downloading all preliminary software, Tony explains the basics:
- Scene view: is similar to that of what a director or game developer would see.
- Game view: is what the gamer would see when the game is run
- Keeping a working log: makes it easier to keep track of errors, issues, and bugs encountered during the development process.
- Hierarchy: located at the left hand side of the interface where all the essentials and objects are listed in.
- Project window: can be imagined as a “warehouse” where all materials and objects are stored in.
- Inspector: allows all sorts of manipulations to be made to a specific material/object.
Creating your First Game object
Tony creates his first game object by navigating towards hierarchy and right-clicking. Naming the first game object as a cube, he manipulates the cube’s qualities by using the inspector window, which displays all of the cube’s properties, such as the cube’s position, material, lighting, etc.
Changing Game Object Properties
Dragging the green material towards the cube, Tony changes the cube’s material to the shade of green. He experiments further by creating a capsule on top of the cube. Tony ends this segment by encouraging us to tinker around with object qualities, materials, and other qualities with the inspector panel.
The Physics Component
In the next segment, Tony incorporates Unity’s built-in game physics to objects. He creates a new object he calls “player” and uses the inspector panel to assign values to the player’s mass, gravity, and collision. He explains that assigning two or more objects with Box collider properties would enable the objects to communicate and detect collision, closure, and distance. These components can then be used to program a command in the form of a “script”.
Writing your First Script with VsCode
Unity game engine uses the Csharp programming language to write scripts; it also needs an IDE, such as VsCode, for scripts to be written and compiled. For the first script, the goal was to create a jumping mechanism that allows “player” object to jump up. Tony does this by writing an “if” statement in line 16 to track and log whenever the player presses the spacebar button. Followed by a debugger/logger in line 18 that gives the result “Space key has been pressed” whenever the if statement is fulfilled.
After testing was successful, he incorporates the “Rigidbody” game physics component that changes the object’s velocity whenever the spacebar was pushed; the final script code follows:
Line 18 is now a physics component that changes the “player” object’s position (x,y,z). It uses the Rigidbody game physics component to push the object up, change its velocity, and its position in the z-axis; this simulates a jumping motion. Tony improves player movements by writing another script that allows the player to move in the horizontal and vertical axis.
The tutorial concludes with a challenge: how do we limit the number of jumps the player object can make? Tony challenges us to write a command that limits the number of jumps the player can make to one.