0% found this document useful (0 votes)
10 views11 pages

Game Development: Hat Trick Tutorial

This document provides a step-by-step tutorial for creating a 2D game project using Unity, including setting up the project, downloading assets, and configuring player and environment components. It details how to add scripts and components to the player object, as well as how to test and debug the game. The tutorial also addresses a bug in player movement and guides users on how to fix it.

Uploaded by

anthonysalman20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

Game Development: Hat Trick Tutorial

This document provides a step-by-step tutorial for creating a 2D game project using Unity, including setting up the project, downloading assets, and configuring player and environment components. It details how to add scripts and components to the player object, as well as how to test and debug the game. The tutorial also addresses a bug in player movement and guides users on how to fix it.

Uploaded by

anthonysalman20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Game Development Workshop

Hat Trick Tutorial


• Create a new project by clicking on the NEW button.

• Select 2D template,Enter project name, Select the Location to save the project.
Game Development Workshop

This Window will be shown.

Click on Default
and select Tall

Download all the assets from the google drive link


[Link]
Folder names
• Sound
• Sprites
• Font

Drag and drop them in the project window


Game Development Workshop

Right click in the hierarchy window.


Tap on Create Empty.
Right
Click
Here

• Click on the Empty Object


• Rename the Empty Object to Player
• Drag and Drop HatFrontSprite on the player object
• Drag and Drop HatBackSprite on the player object
• Set the transform Values To the values in the Black Box
• Select HatFrontSprite and set the transform value to the value in the
black box, Repeat this step again for HatBackSprite.
Game Development Workshop

Click on Add Component Button like in the image below


Type BoxCollider2D and click on it.
Set the BoxCollider2D values same as the values in the picture below.

Click on Add Component Button


Type RigidBody2D and click on it.
Set the RigidBody2D values same as the values in the picture below.

1. Click on the game window Tap on Free Aspect click on 16:9


2. Drag and Drop Ground Sprite and SkySprite
3. Select the SkySprite and set the order in Layer -2
4. Select the GrassSprite and set the order in Layer -1
Game Development Workshop

Select the Main Camera from the hierarchy and change the size value from 5 to 10 in the camera
component like in the image below.

Select the Player and set its transform values to the values in Image below.

Select the GrassSprite and set its transform values to the values in the image below.

Select the GrassSprite and add a box collider as we did before on the player and set the collider
values to the values in the image below.
Game Development Workshop

Select the Player and click on AddComponet and Type PlayerController


Click on New Script

Click on Create and Add button

Wait for compiler to create,


compile and attach the script the
Player.

PlayerController will be added like


the image on right.
Double click on PlayerController
highlighted in the image or right
click and tap on edit script and will
open the script in the Visual Studio
Game Development Workshop

Write the code from the image below in the script

Open Unity and give it a 10-15 seconds to compile.


Game Development Workshop

Press CTR + SHIFT + C


Drag the Console window from the start of the arrow and drop it in the bottom.

Console window will look like this.


Click on Play Button to start the game.
Press A or D to test the script.
Debug statements will start printing in the console.
Press the Play button again to Stop the game.

Note all the changes applied in the Play mode (when the play button is blue will not be saved).
Game Development Workshop

Change the PlayerController code and write the code in the image below
Game Development Workshop

Open Unity wait 10-15 seconds for the code to compile.


Press Play and move the player with A and D
Note the player will not move.
All the public variables we created in the PlayerController scripts are Available to us in the editor

Set the Values on the PlayerController to the values in the image below.

Click On play button to check your code.


Press A To move Left and D To move Right
Note there is a bug the player moves to right when we press A and vice versa.
Lets Fix this bug.
Open the PlayerController Script again and apply the following changes.

Open Unity again, wait 10-15 seconds for the new code to compile and press Play to test the
changes.
Game Development Workshop

Common questions

Powered by AI

The Unity console is an essential tool for monitoring debug statements that print script behavior during the game's runtime. To utilize it effectively, drag the console window to a convenient location in the Unity interface and observe for any debug messages while interacting with the game. This feedback helps identify logical errors or confirm expected outcomes during testing. It is crucial to regularly check the console for unexpected errors or warnings that could indicate issues within the scripts.

To set up a project in the Game Development Workshop tutorial, the user must create a new project by clicking on the NEW button, select a 2D template, enter the project name, and choose the location to save the project. The user then downloads all necessary assets from the provided Google Drive link and drags and drops them in the project window. The next step is to select 'Default' and choose 'Tall.'

The sprite assets are incorporated into the player object by dragging and dropping the 'HatFrontSprite' and 'HatBackSprite' onto the player object. The user must then set the transform values of these sprites as per the specified values given in the tutorial. This process ensures the sprites are correctly positioned and aligned on the player object.

To fix reversed directional input issues, review the PlayerController script to confirm the implementation of input mappings and modify logic to correctly map inputs to action-reversal actions. This could involve revisiting and revising input clauses or conditions that handle movement logic. Testing adjustments iteratively, while using the Unity console for debugging, is crucial to isolate and fix logic errors efficiently. Ensuring the correct axes are referenced in control mappings can also resolve such issues.

The Main Camera transformation is adjusted by changing its size value from 5 to 10, influencing how much of the scene is visible on-screen. The GrassSprite's transform values are also set according to the guidance, which may include position, scale, and pivot modifications. Additionally, a box collider is added to the GrassSprite with specific collider values to ensure collision detections are accurate.

Compilation in Unity is the process whereby scripts are translated into a runnable format within the Unity environment. After modifying the PlayerController script, waiting for Unity to compile the changes is crucial, as it allows see if modifications result in intended functionality without errors. Compilation ensures that all scripts are up-to-date with the latest code edits, a fundamental step before testing or running the game in Play mode.

Writing the PlayerController script involves creating and attaching a new script to the player object. The user writes the specified code in Visual Studio, after which Unity is allowed 10-15 seconds for compilation. Testing involves pressing the Play button in Unity and using the 'A' and 'D' keys to see the player movement. Debug statements help verify script functionality in the console. Changes in Play mode will not be saved once stopped, a critical point to remember during testing.

To configure a BoxCollider2D in the tutorial, click on the Add Component Button, type 'BoxCollider2D,' and select it. The user must set the BoxCollider2D values to match those in the guide. Similarly, to configure a RigidBody2D, repeat the adding component steps, type 'RigidBody2D,' and set its values according to the tutorial's instructions. These components are crucial for adding physics interactions to the player object.

Incorrect settings of public variables in the PlayerController script can lead to dysfunctional movement or unexpected behavior of the player object, such as moving in the wrong direction. These issues are resolved by carefully setting the public variable values within the Unity editor as specified in the tutorial. Debugging involves identifying discrepancies in expected behavior versus actual behavior and updating the script accordingly. In the tutorial, a noted bug is resolved by modifying script details to correct player movement directions.

Layer ordering is significant as it determines the render order of the sprites in the 2D scene. In the tutorial, the 'SkySprite' is set to layer -2 and 'GrassSprite' to layer -1, ensuring the sky appears in the background and the grass is above it but below other elements. Proper layer management prevents visual overlap issues and ensures a coherent scene composition.

You might also like