A feature-rich slot machine built in Unity to demonstrate clean structure, RNG fairness, animation, and bonus mechanics.
- Open
Build/WebGL/index.htmllocally via a static server. - Or host the
/Build/WebGLfolder on GitHub Pages (see below).
Assets/
Art/
Audio/
Prefabs/
Reels/
UI/
Scenes/
Main.unity
Scripts/
Core/
Gameplay/
Reels/
Symbols/
Features/
UI/
Build/
WebGL/
- 3Γ3 reel layout with smooth spin animations
- Win condition: match symbols on paylines
- Paylines: 5 standard lines (3 rows + 2 diagonals)
- Clean RNG (crypto-seeded for fairness)
- Configurable payouts via ScriptableObjects
- Balance system with spin cost and payouts
- Wild symbols β substitute any match
- Scatter symbols β trigger free spins (3+ scatters)
- Weighted rarity β control symbol frequency
- Animator option β blur reel spin animations
- Paylines easily expanded
- Free spins stackable
- Bonus features isolated in separate scripts
- Fully data-driven using ScriptableObjects
Canvas
βββ UIController (scripts for spin button, balance text)
βββ SpinButton
βββ BalanceText
SlotMachineController
βββ ReelContainer (empty parent)
βββ ReelView_0
βββ ReelView_1
βββ ReelView_2
AudioManager
- Symbol prefab β Image + Symbol script
- Reel prefab β Empty with VerticalLayoutGroup, holds symbols
- UI prefabs β Button, Text
- Create
Canvas(UI Scale Mode: Scale With Screen Size). - Add Spin Button and Balance Text.
- Create empty
SlotMachineControllerGameObject β attachSlotMachineController.cs. - Inside it, create
ReelContainerβ add 3 child objects:ReelView_0, ReelView_1, ReelView_2. - Each ReelView prefab: attach
ReelView.cs. - Create Symbol prefab: attach
SymbolView.cs, link sprite in inspector. - Drag reels and symbols into controller references.
- Link Spin Button β
UIController.OnSpinClicked().
Add a .gitignore in repo root:
[Ll]ibrary/
[Tt]emp/
[Bb]uild/
[Bb]uilds/
obj/
[Mm]emoryCaptures/
[Bb]in/
/Logs/
*.csproj
*.unityproj
*.sln
*.userprefs
.DS_StorePlace in Assets/Editor/AutoWireReels.cs:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(SlotMachineController))]
public class AutoWireReels : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
SlotMachineController controller = (SlotMachineController)target;
if (GUILayout.Button("Auto-Wire Reels"))
{
var reels = controller.GetComponentsInChildren<ReelView>();
controller.Reels = reels;
EditorUtility.SetDirty(controller);
Debug.Log($"Wired {reels.Length} reels.");
}
}
}classDiagram
class SlotMachineController {
- ReelView[] Reels
- RNGService rng
- Wallet wallet
+ Spin()
+ EvaluateWin()
}
class ReelView {
- SymbolView[] symbols
+ SpinAnimation()
+ StopAt(SymbolDefinition)
}
class SymbolView {
- SymbolDefinition definition
+ Display()
}
class SymbolDefinition {
<<ScriptableObject>>
- string name
- Sprite icon
- int payout
- SymbolType type (Normal/Wild/Scatter)
- int weight
}
class RNGService {
+ GetRandomSymbol()
+ Seed()
}
class Wallet {
- int balance
+ Add()
+ Deduct()
}
class UIController {
+ OnSpinClicked()
+ UpdateBalanceText()
}
SlotMachineController --> ReelView
ReelView --> SymbolView
SymbolView --> SymbolDefinition
SlotMachineController --> RNGService
SlotMachineController --> Wallet
SlotMachineController --> UIController
-
Started with modular structure (scripts split by domain: core, reels, symbols, features)
-
Used ScriptableObjects for symbol definitions & payouts
-
Centralized RNGService with cryptographic seeding
-
Procedural spin animation with
AnimationCurve -
Extended to 3Γ3 layout with paylines, adding:
- Wilds (flexible symbol match)
- Scatters (bonus trigger)
- Weighted rarity for symbol balancing
-
Provided Animator-driven option for motion blur
-
Ensured WebGL compatibility
- Unity ScriptableObjects
- Unity UI Toolkit
- AnimationCurve
- Coroutines
- WebGL Build Settings
- Object Pooling