0% found this document useful (0 votes)
20 views8 pages

Chess App Workshop 1 Tutorial

Uploaded by

Jeanmes Chila
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)
20 views8 pages

Chess App Workshop 1 Tutorial

Uploaded by

Jeanmes Chila
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
You are on page 1/ 8

How to create a Chess App using Unity

Workshop 1

Prerequisites
-Unity installed (preferably version 2019.3 or newer)
-An IDE (code editor) that is attached to Unity
-When installing Unity also install Visual Studio with it for it to work automatically
-The completed version: https://github.umn.edu/app-developers-club/Chess_App

Let’s Get Started


Open Unity Hub or Unity and create a new project:
● Select 2D
● Name it Chess_App_ADC
● Place it in a folder of your choosing, somewhere that’s convenient to access and store
● Select “Create”
Once it loads change the aspect ratio:
● Click on the “Game” tab
● Click on the aspect ratio drop down menu
● Set it to 9:16, this is standard for apps on phones

Now rename the scene to “Game”:


● Open the “Scenes” folder
● Right click and rename it to “Game”
● Click reload screen
Now navigate back to the assets folder and create a “Game_Assets” folder and put the sprites
in there:
● Click on “Assets”
● Right click and select “create” then select “folder”
● Click on the folder
● Download the assets here: https://devilsworkshop.itch.io/pixel-art-chess-asset-pack
○ This contains almost every image or sprite that will be used in this game
● Unzip the folder chess_green (or chess / chess_pink if you prefer) somewhere on your
computer
● Drag all the images into the “Game_Assets” folder
● Once this is done they have all been imported in
● Select all the assets in the Game_Assets folder (CTRL + CLICK)
● Set filter mode to: Point (no filter)
○ This will make sure the sprites do not look pixelated when scaled
● Click somewhere else and select apply

Add the chess board to the scene:


● Click on the “Scene” button to get out of the “Game” view
● Drag the picture of “board” into the scene (the gray grid part)
● On the right side information now appears
● Rename the asset to “Board” as our game objects should have capital names
● Set the X and Y positions to 0
● Set the X and Y scales to 3

Change the background color:


● Click on “Main Camera” from the “Game” selection
● Click on the section: Background
● Make it Black (or whatever color you prefer)
Creating the Chesspiece game object:
● Navigate back to the “Assets” folder
● Create a new folder named “Objects”
● Click on this folder
● On the top of the screen select the “GameObject” drop down menu
● Select create empty
● Rename it “Chesspiece”
● Click Add Component and select “Sprite Renderer”

● Select a sprite such as “black_king” and drag it into the “Sprite” section of the sprite
renderer
● Again, set the scale for this object (the X and Y) to 3
● Open the Objects folder
● On the left tab, drag “Chesspiece” down to the “Objects” folder
● This has created a prefab for us to use
● Now delete the object from the left tab, which will remove it from the screen
○ We will spawn these chess pieces in ourselves through code, trust me it will be
easier than setting the positions one by one
Create a controller:
● This is the most important object for this and most games!!!!
● Navigate to “GameObject” from the top drop down menu and create another empty
object
● Rename it to “Controller”
● Drag it above “Main Camera” in the Hierarchy menu as it is the most important
GameObject
Spawn the Chesspiece:
● Navigate back to “Assets” and create a “Scripts” folder
● Click on the folder
● Right click and create a “C# Script”
○ C# is the programming language used by Unity
○ Don’t worry if you have never programmed with it as it is similar to Java
● Rename this script to “Game”
○ Make sure the Class in the code itself is the same name
● Click on the controller asset
● Drag the “Game” script into the controller
● Double click on the “Game” script
● It should now be open with either Visual Studio Code or an IDE that you commonly use
● Inside here there are already Start() and Update() functions
○ Start(): run once at the Start of the game
○ Update(): run every frame
○ There are many more built-in functions provided by Unity and of course you can
create your own
● Delete the Update() function
● Above the Start() function type the following code:

● This is a variable (attribute) that Controller will contain


● It will allow us to reference the Chesspiece asset we have created in Unity
● Click back on Unity, click on the Controller in the Hierarchy again
● Click on the Objects folder
● Drag the Chesspiece object to the “Chesspiece” section in the “Game” script that has
now appeared
● Once that is complete, there is now a reference in the script to the Chesspiece, it will be
possible to create this object through code now
Instantiating the object:
● Inside the start function write the following code
○ Instantiate(chesspiece, new Vector3(0, 0, -1), Quaternion.identity);
○ Instantiate is used to create an object in the game
○ The second argument is for a location, in the form of a Vector3
○ We need to set up its rotation which is not so important in 2D games so just
setting it to Quaternion.identity is good enough
● This is all that’s needed to spawn the chess piece into the game
● Go back to unity and press the play button that is on the middle on top
● You can now see the game working

You might also like