Simple Chess
Recreating chess in Unity URP
Intent
Goal
Play At
Software
Test the limits of using basic C#, gain URP & shadergraph experience.
A chess game, using Unity URP, Shadergraph, and beginner-level C#
Skills improved
- Unity
- Visual Studio
- C#
- Unity URP pipeline
- Debugging Unity in VS
- Unity prefabs
- Unity UI
- Shadergraph & Shaders
- Programming: Turn-based system, Camera animations
Testing the limits of beginner-level C#
This project was initially goaled to test the limits of my beginner-level C#, to prepare to
learn intermediate & advanced C# after.
I found it a good way to also introduce myself to Unity's URP pipeline and the Shadergraph,
by creating some shaders, and applying post-processing.
The eventual goal: Recreate chess using only my beginner C# skills, whilst gaining some proficiency in the URP pipeline and shadergraph.
Creating the game
I Started with getting a chess 3D model package, created prefabs for each chess pawn, created the board, and created a set of base-colour materials for them.
Programming chess would rely on having a coordinate system for the pawns to operate on. Using the board dimensions, I kept scale 1x1 for each pawn, and created a coordinate grid based on that scale. The pawn class stored the coordinates individually.
I used Unity's MonoBehaviour-provided OnMouseClick() functions to call logic to select/deselect pawns. For the pawn mechanics I had to implement 3 things: Inherit separate pawn classes from the base pawn class, Add specific mechanics to each specific pawn class, and add detection logic if another pawn is blocking movement possibilities.
With functional pawns, I implemented a turn system: Ending a player's turn after a move and switching board sides to the other player. To make this process feel smooth, I added logic for camera animation: Lerping smoothly from one side to the other.
With a nearly functional game, I added in enemy detection to my pawn movement logic. With detectable enemies, I could now implement the capture mechanic for pawns labelled "capturable".
All that was left was to add a scoring system based on pawn captures, add a game-end condition on the queen, and add some simple UI.
URP & Shadergraph
To gain some proficiency in URP, I decided to create a shader using the shadergraph, and add a global post processing volume.
To create the shader, I followed a (good old) Brackeys
tutorial on YouTube. I re-used the base I got from that tutorial to change a few things so I got
the look I wanted for my pawns.
This allowed me to get used to navigating the shadergraph, it's node system, and basic
functions.
For post-processing, I decided to keep it simple and add a global volume to create bloom. This was straightforward and simple to achieve.