Skip to main content
โ€น Back to Tutorials
Intermediate Unity

Making a Mobile Bounce Game with Unity 3D and Playmaker - Adding Score to Game

Dec 23, 2020
About this tutorial

Beginner Game Design tutorial series creating a simple Bounce type game using Playmaker within Unity 3D. In Part 4, we will add Score and a Score UI. Absolutely NOCODE. Also learn to make a skateboard game playlist: https://bit.ly/34m4SHT ๐Ÿ‘‰๐Ÿผ To Sign up for email updates on my latest tutorials a

Written Guide

Adding a score is what turns a bounce toy into an actual game, and in this fourth part of the mobile Bounce series we wire up scoring with Playmaker and no code at all. The plan is simple: every time the ball strikes the paddle, the score goes up by one, and that running total is shown on screen through a small UI built with TextMesh Pro. Picking up from the previous part, the paddle already moves and the ball already has a trail, so the only work left is the data and the display.

Building the Score UI

Start by keeping things organized. Create an empty folder named ui to hold all interface elements, then add a UI Canvas inside it and rename the canvas ui-score. Drop an Image onto the canvas to act as the backdrop behind the number, rename it score background, and slide it to the top of the screen. Widen it to about 300 so it has room, then recolor it toward the dark pink and purple theme of the game so it sits nicely against the play area.

Next add a TextMesh Pro text object, name it score text, and position it on top of the background, matching its bounds to the backdrop. Set the placeholder text to XXX so you can see five character slots, make it bold, bump the font size up to around 60, and tint it slightly off-white rather than pure white so it is easier on the eyes. Center the text both horizontally and vertically inside the box.

Creating the Score Variable

Open Playmaker's global variables and add a variable named score of type int. An int is a whole number with no decimal point, which is exactly right for a score because you never want a value like 1.2. Using a global means any FSM in the project can read or change the same score.

Updating the On-Screen Number

Create an empty game object called managers, and inside it another empty named score manager. Add an FSM to it called update ui whose only job is keeping the displayed number in sync. The display is a string of text, but the score is an int, so add a Convert Int to String action that reads the global score and writes it into a new string variable named score text, with Every Frame enabled.

Now push that string to the screen. Lock the score manager in the inspector so it stays selected, drag the score text UI element into the state, and add a Set Property action. Scroll down to the text option, choose the text string property, and feed it the score text variable by unchecking the variable box and selecting it. Pressing play now shows 0 on screen.

Detecting the Hit and Incrementing

Add a second FSM to the score manager named paddle hit for collision detection. Add a Collision Event action, drag in the paddle as the game object to watch, set the collide tag to ball, and fire a new event called add to score. Wire that transition to a new state named add to score, where an Int Add action targets the global score and adds 1. Leave Every Frame off so each contact counts only once, then add a finished transition back to the listener state. Now every paddle bounce records a point and the UI updates live. Up next in the series is adding a game over when the ball reaches the bottom of the screen.

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 →