Skip to main content
‹ Back to Tutorials
Intermediate Unity

How to Make a Skateboard Game with Unity and Playmaker - Part 4 - Adding an Enemy and a Game Over UI

Dec 6, 2020
About this tutorial

In part 4 of this series, we will be adding an enemy game object, setting up a trigger event to detect if we hit it, and also creating a simple game over UI and turning on the UI when the enemy is detected. We will use Unity and Playmaker, then also import character and animations from Mixamo and t

Written Guide

Part four of this skateboard game series adds an obstacle the player must avoid, a police car, and the game-over flow that fires when the player hits it. Using free models from Kenney plus Unity and Playmaker, you'll place the car, set it up as a trigger, and build a Game Over UI that appears while time freezes.

Import and place the car model

Search Kenney's assets for a car kit and download it (consider donating to support the creator). Import just a couple of the FBX models into your Models folder. Create an empty game object named Cars for organization and add a police car. If it jumps far away, reset its position to 0, 0, 0, then rotate it 180 degrees on the Y axis and scale it to roughly 2, 2, 2 so it reads well against the character.

Build the police prefab with physics

Create an empty game object called Police, parent the car model under it, and add a Rigidbody with Use Gravity on; freeze rotation or set it kinematic since it shouldn't move. Add a Box Collider and size it to the vehicle, keeping it slightly generous but a touch smaller so the player gets a fair break jumping over it. Make this a static object, then drag it into your Prefabs folder. Assign the predefined Enemy tag and check Is Trigger on the collider so the character can detect it. Duplicate the prefab down the scene to create obstacles to avoid.

Detect the enemy with a Playmaker FSM

Select the player and add a new FSM named Enemy Detection. Add a Trigger Event action set to On Trigger Enter on the owner, with the collide tag set to Enemy. When the character collides with an enemy, send a new event called Game Over, add its transition, and create a Game Over state to handle the result.

Freeze time on game over

In the Game Over state, add a Scale Time action and set time to 0 so the player stops moving down the scene and the game effectively pauses. Because this is driven by a variable, you could animate the slowdown for a smoother effect, but setting it straight to zero stops everything immediately.

Create and show the Game Over UI

Add a UI Panel, which also creates a Canvas. Set the Canvas to Scale With Screen Size with a reference resolution of 1920 x 1080 (or 1280 x 700) and screen match mode set to Expand so it adapts. Darken the panel color, then add a TextMesh Pro text element reading GAME OVER in all caps, centered, with the font size bumped to about 120. Name it Game Over UI and turn it off. Back in the Game Over state, add an Activate Game Object action with the box checked, targeting the Game Over UI so it appears the moment the enemy is hit.

Unity tools by Bliz Studio
Built for our own games — now on the Asset Store

Multi Tag — unlimited hierarchical tags for any GameObject. Hierarchy Pro — style your whole hierarchy with rules. Made by a Unity dev, for Unity devs.

Explore our Unity assets →