Skip to main content

How to Build a Slot Game in Unity: A Working 3-Reel Prototype

· 13 min read
Founder, Gamix Labs

Updated

How to build a slot game in Unity

Most Unity slot tutorials pick a random sprite for each reel and call it a slot machine. It spins, but it has no reel strips, no paytable you can reason about and no idea what it pays back. You can't turn that into a real game.

This guide builds a small 3-reel slot that works the way production slots do. The math lives in plain C#, separate from Unity. The reels only animate to a result that was decided before they started. And you can check the game's return to player (RTP) yourself. Every script below was compiled, and the math was run for 30 million spins while writing this guide.

What you'll build​

  • 3 reels, 3 visible rows, one payline across the middle row.
  • 5 symbols: Seven, Bar, Bell, Cherry and Lemon.
  • A balance, a fixed bet and a Spin button.
  • Reels that scroll and stop left to right on the result.
  • A built-in RTP check you can run from the Inspector.

You need Unity 6 or 2022.3 LTS, a new 2D project, and five symbol images. No paid plugins.

How the code is split​

Three scripts, each with one job:

ScriptJobUses Unity?
SlotMath.csReel strips, the spin result, the paytable, RTPNo
ReelView.csShows one reel and animates it to a given stopYes
SlotGame.csTakes the bet, asks the math for a result, spins the reels, paysYes

The important line is between the first script and the other two. SlotMath never touches a sprite, and the views never decide a result. That is how our own Unity slot client is built: the math is a separate C# library that the game server, the simulator and the Unity client all share, and the client only plays what the math returns. It means you can test the math without opening Unity, and later move it to a server without rewriting it.

Step 1: Set up the scene​

  1. Create a new 2D project and import your five symbol images. Set each one's Texture Type to Sprite (2D and UI).
  2. Add a Canvas (GameObject > UI > Canvas). Set Canvas Scaler to Scale With Screen Size with a reference resolution of 1920 × 1080, so the layout holds on any screen.
  3. Inside the Canvas, add an empty object called Reels with a Horizontal Layout Group.
  4. Inside Reels, add three objects called Reel1, Reel2 and Reel3, each with a Vertical Layout Group and three Image children. Those nine Images are your visible grid.
  5. Add a Button - TextMeshPro for Spin, and two Text - TextMeshPro objects for the balance and the win. Unity will offer to import the TMP essentials the first time: accept.

Step 2: Write the slot math​

Create SlotMath.cs. Nothing in it uses UnityEngine.

using System;

// Pure C# slot math: no UnityEngine, so it runs in Unity, on a server or in a test.
public class SlotMath
{
public const int Seven = 0, Bar = 1, Bell = 2, Cherry = 3, Lemon = 4;
public static readonly string[] Names = { "Seven", "Bar", "Bell", "Cherry", "Lemon" };

// One strip per reel. How often a symbol appears on a strip sets its odds.
public readonly int[][] Strips =
{
new[] { 4, 3, 2, 4, 1, 3, 4, 2, 3, 0, 4, 3, 2, 4, 1, 3, 4, 2, 3, 4 },
new[] { 3, 4, 2, 3, 1, 4, 3, 2, 4, 0, 3, 4, 2, 3, 1, 4, 3, 2, 4, 3 },
new[] { 4, 2, 3, 4, 1, 2, 4, 3, 2, 0, 4, 2, 3, 4, 1, 2, 4, 3, 2, 4 },
};

// Pay for three of a kind on the middle row, as a multiple of the bet.
public readonly int[] ThreeOfAKind = { 500, 100, 20, 10, 5 };
public const int TwoCherries = 2; // cherries on reels 1 and 2

public int[] Spin(Random rng)
{
var stops = new int[Strips.Length];
for (int r = 0; r < Strips.Length; r++)
stops[r] = rng.Next(Strips[r].Length); // every stop equally likely
return stops;
}

public int SymbolAt(int reel, int stop, int rowOffset)
{
int[] strip = Strips[reel];
int i = (stop + rowOffset) % strip.Length;
if (i < 0) i += strip.Length;
return strip[i];
}

// Win as a multiple of the bet, read from the middle row.
public int WinMultiplier(int[] stops)
{
int a = SymbolAt(0, stops[0], 0);
int b = SymbolAt(1, stops[1], 0);
int c = SymbolAt(2, stops[2], 0);
if (a == b && b == c) return ThreeOfAKind[a];
if (a == Cherry && b == Cherry) return TwoCherries;
return 0;
}

// Exact RTP: try every combination of stops once.
public double ExactRtp()
{
long total = 0, combos = 0;
var s = new int[3];
for (s[0] = 0; s[0] < Strips[0].Length; s[0]++)
for (s[1] = 0; s[1] < Strips[1].Length; s[1]++)
for (s[2] = 0; s[2] < Strips[2].Length; s[2]++)
{
total += WinMultiplier(s);
combos++;
}
return (double)total / combos;
}
}

A spin is just three numbers: one stop per reel, each from 0 to 19. The random number generator treats every stop the same. The odds come from the strips. Each reel has 20 stops but only one Seven, so three Sevens happen once in 20 × 20 × 20 = 8,000 spins. Lemons fill 6 or 7 stops per reel, so they line up far more often.

Step 3: Check what the game pays back​

Before drawing a single reel, look at what this math pays. With only 8,000 possible results, ExactRtp() can check every one of them:

WinPaysHappensShare of RTP
3 Sevens500x1 in 8,0006.25%
3 Bars100x1 in 1,00010.0%
3 Bells20x1 in 8324.0%
3 Cherries10x1 in 4821.0%
3 Lemons5x1 in 2718.4%
2 Cherries2x1 in 1216.8%
Total1 in 6.5 spins pays96.43%

So over a very long run this game returns 96.43% of everything bet. Change one number in a strip or the paytable and this table changes, which is exactly how studios tune a real game.

A simulation tells you something the exact number doesn't. In one run of 1 million spins the game returned 97.67%, not 96.43%. Three runs of 10 million spins came out at 96.11%, 96.45% and 96.57%. The rare 500x Seven swings short runs, and the 95% range around the true RTP is about ±1.4% at a million spins and ±0.14% at a hundred million. That is why real slots are simulated for hundreds of millions of spins before certification.

Step 4: Make a reel​

Create ReelView.cs. It shows three rows of one reel and can animate to any stop it is told to.

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

// Shows one reel: three Images stacked top, middle, bottom.
// It never decides anything. It only plays a spin and lands on the stop it is given.
public class ReelView : MonoBehaviour
{
public Image[] rows = new Image[3]; // 0 = top, 1 = middle, 2 = bottom
public float symbolsPerSecond = 20f;

SlotMath math;
Sprite[] symbolSprites;
int reelIndex;
int position; // the strip index currently shown on the middle row

public bool IsSpinning { get; private set; }

public void Init(SlotMath slotMath, Sprite[] sprites, int index)
{
math = slotMath;
symbolSprites = sprites;
reelIndex = index;
position = 0;
Show();
}

// Scrolls for spinSeconds, then steps on until the target stop is on the middle row.
public IEnumerator SpinTo(int targetStop, float spinSeconds)
{
IsSpinning = true;
int stripLength = math.Strips[reelIndex].Length;
float step = 1f / symbolsPerSecond;
float elapsed = 0f;

while (elapsed < spinSeconds || position != targetStop)
{
position = (position - 1 + stripLength) % stripLength; // symbols move down
Show();
yield return new WaitForSeconds(step);
elapsed += step;
}

IsSpinning = false;
}

void Show()
{
for (int row = 0; row < rows.Length; row++)
{
int symbol = math.SymbolAt(reelIndex, position, row - 1); // -1, 0, +1
rows[row].sprite = symbolSprites[symbol];
}
}
}

The reel walks through its own strip in order, so the symbols the player sees scroll past are the real neighbours on that strip. It keeps going for at least spinSeconds, then stops the moment the target stop reaches the middle row. Add it to Reel1, Reel2 and Reel3, and drag each reel's three Images into Rows, top to bottom.

Step 5: Run the game loop​

Create SlotGame.cs and add it to the Canvas.

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

// Runs the game loop: take the bet, ask the math for a result, spin the reels to it, pay.
public class SlotGame : MonoBehaviour
{
public ReelView[] reels = new ReelView[3];
public Sprite[] symbolSprites = new Sprite[5]; // Seven, Bar, Bell, Cherry, Lemon
public Button spinButton;
public TMP_Text balanceText;
public TMP_Text winText;

public int balance = 1000;
public int bet = 10;
public float firstReelSeconds = 1.0f;
public float extraSecondsPerReel = 0.35f; // reels stop left to right

readonly SlotMath math = new SlotMath();
readonly System.Random rng = new System.Random(); // prototype only: real money needs a server RNG

void Start()
{
for (int i = 0; i < reels.Length; i++)
reels[i].Init(math, symbolSprites, i);
spinButton.onClick.AddListener(OnSpin);
UpdateUI(0);
}

void OnSpin()
{
if (balance < bet) return;
StartCoroutine(PlaySpin());
}

IEnumerator PlaySpin()
{
spinButton.interactable = false;
balance -= bet;
UpdateUI(0);

// The result is decided here, before any reel moves.
int[] stops = math.Spin(rng);
int win = math.WinMultiplier(stops) * bet;

for (int i = 0; i < reels.Length; i++)
StartCoroutine(reels[i].SpinTo(stops[i], firstReelSeconds + i * extraSecondsPerReel));

foreach (var reel in reels)
while (reel.IsSpinning) yield return null;

balance += win;
UpdateUI(win);
spinButton.interactable = balance >= bet;
}

void UpdateUI(int win)
{
balanceText.text = $"Balance: {balance}";
winText.text = win > 0 ? $"Win: {win}" : "";
}

// Right-click the component in the Inspector and pick this to check the math.
[ContextMenu("Check RTP")]
void CheckRtp()
{
Debug.Log($"Exact RTP: {math.ExactRtp():P2}");
var testRng = new System.Random(1);
long paid = 0, spins = 1_000_000;
for (long i = 0; i < spins; i++) paid += math.WinMultiplier(math.Spin(testRng));
Debug.Log($"Simulated RTP over {spins:N0} spins: {(double)paid / spins:P2}");
}
}

In the Inspector, drag in the three reels, the five sprites in the order Seven, Bar, Bell, Cherry, Lemon, the Spin button and the two texts. Press Play and spin.

Three details in PlaySpin matter more than they look:

  • The bet comes off first. If the game closes mid-spin, the player has paid for a result, not the other way round.
  • The result is decided before the reels move. The animation is just a way of showing it. That is how every real slot works.
  • The button is off while reels spin. Without that, a fast double tap starts two spins at once, which is one of the most common bugs in first slot prototypes.

To check the math inside Unity, right-click the SlotGame component and choose Check RTP. The Console prints the exact RTP and a million-spin simulation.

Step 6: Make it feel like a slot​

The prototype works. These are the next things that make it feel finished, roughly in the order studios add them:

  • Reel stop bounce. A short overshoot and settle on each stop. A tween library such as DOTween, or an AnimationCurve you write yourself, does it in a few lines.
  • Win presentation. Highlight the payline and animate the winning symbols. Most commercial slots animate symbols in Spine, which keeps files small and runs well on mobile.
  • Sound. Separate sounds for spin start, each reel stop and the win, with the win sound scaled to the win size.
  • Anticipation. When the first two reels show a possible big win, slow the last reel down. Because the result is already known, this is purely a presentation choice.
  • A state machine. As soon as you add free spins or a bonus game, a simple if in PlaySpin stops being enough. Our production client drives everything from game states (idle, spinning, spin end, win, free spins, bonus), and each effect listens for the states it cares about.

Step 7: Build for WebGL or mobile​

Open File > Build Settings (in Unity 6, Build Profiles), pick WebGL, Android or iOS, and build. For WebGL, turn on compression in Player Settings and test in a real browser, because the editor hides loading time. Test both portrait and landscape on a phone, and check that the Canvas Scaler keeps the reels and buttons where you expect.

From prototype to a real slot​

This project is a good way to learn how slots work, and it is a fair base for a social casino game where no real money changes hands. A real-money slot needs a few things this one deliberately skips:

  • The RNG and math move to a server. In real-money games, the client never decides results. It sends the bet and plays back what the server returns. Our guide on how RNG works in slot games explains what that server-side RNG has to do.
  • Math is designed and proven, not guessed. Features such as free spins, multipliers and bonus games change the RTP and volatility, and each version is simulated for hundreds of millions of spins.
  • Certification. An independent lab tests the RNG and the game before it can go live in regulated markets.
  • Integration. The game has to talk to the operator's wallet and platform, such as an aggregator or Stake Engine.

If you are planning a commercial slot, our slot game development team handles the art, animation, math, integration and QA. For Stake Engine projects, see our Stake Engine development offer, or send us your game brief.

Frequently Asked Questions​

Can I build a slot game in Unity without paid plugins?

Yes. The prototype in this guide uses only Unity's built-in UI, TextMeshPro and three C# scripts. Plugins such as DOTween or Spine help with polish later, but they are not needed to get a working slot.

Should I use Random.Range to pick symbols?

Picking a random symbol per reel gives you no control over the odds. Use reel strips instead: pick a random stop on each strip, and set each symbol's odds by how many times it appears on the strip. That is also what lets you calculate the game's RTP.

How do I set the RTP of a Unity slot game?

Change how often each symbol appears on the reel strips and what each win pays, then measure. For a small game you can check every combination of stops exactly; for larger games you simulate millions of spins. The example in this guide returns 96.43%.

Can I add more reels or paylines later?

Yes. Add a strip per reel in SlotMath, add the reel to the scene, and check each payline in WinMultiplier instead of only the middle row. Then rerun the RTP check, because every change moves it.

Can I publish this as a real-money slot?

Not as it is. A real-money slot needs the RNG and math on a server, a certified game build, and integration with a licensed operator's platform. It is a sound base for learning or for a social casino game with no real-money play.