Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity + Playmaker - Counting Clicks on UI Button

Aug 13, 2021
About this tutorial

This is part 2 of a recording, I'm setting up the Fuel button and counting clicks in Playmaker and how fast I can click. I'm also setting up the beginning launch rocket smoke particle system in Unity. These videos are uncut but I have compressed time to make them shorter. ► Please Join my Discor

Written Guide

This part of a three-hour game jam build wires up the click-to-fuel mechanic for a rocket launch game. The goal is a button players mash to add fuel during a fixed five-second window, a timer bar that drains as they go, a live click count on screen, and a particle exhaust that fires once the rocket lifts off. Everything runs through Playmaker FSMs on a central game manager so the logic stays in one place.

Count the button clicks

Create an FSM on the game manager called Click Counter. Add a UI Button On Click Event to the fuel button and have it send a new event named button clicked, transitioning to an Add To Click Count state. Because you want every press counted, wire a Finished transition straight back so the FSM keeps listening. Store the tally in a global int named spacex count so other systems can read it, and use Int Add to increase it by one each time the state runs. Testing shows the number climbing as fast as you can click.

Drain a five-second timer

Add a second FSM called Timer. Tween a float variable from 1 down to 0 over five seconds using linear easing with real time enabled, matching the radial fill that starts full. When the tween finishes, send a launch event by name to the Click Counter FSM so it can shut things down. To make the bar visibly empty, lock the FSM, add a UI Set Fill Amount action that updates the timer image every frame from that same float, so the float drives both the countdown and the on-screen fill.

Disable the button and show the count

Set up a global launch transition on the Click Counter that uses Activate Game Object to deactivate the fuel button and the timer circle once time is up. For feedback during play, add a TextMesh Pro element, convert the global spacex count int to a string, and use Set Property on the text object to push that string into its text value. There is no need to update every frame, only when the count changes.

Add the rocket exhaust and liftoff

Build a particle system rotated to face down, with a long duration, particle lifetimes around one to two, larger random start sizes of three to five, an alpha fade in color over lifetime, and emission cranked to roughly 100 per second for a dense plume. Parent it to the ship as rocket smoke, reset its position, and leave it disabled. On the launch event, Activate Game Object to switch it on. Finally, sell the liftoff by tweening the ground plane down to about negative 78 over five seconds with a quad ease so it accelerates away, giving the illusion the rocket is rising.

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 →