A powerful and production-ready Spin Wheel System for Unity. Features weighted reward probability, a daily cooldown system, watch-ad spins, and an event-driven reward system for easy integration with your game's economy.
- Dynamic Reward Configuration: Easily set up 8 distinct rewards from the Inspector, including their name, amount, type (e.g., Coins, Gems), rarity, and probability weight.
- Weighted Probability Engine: Precisely control the chance of landing on each reward. Higher weights mean higher probability.
- Event-Driven Rewards: Fires a C# event (
OnRewardWon) when a reward is won, allowing you to cleanly integrate it with any currency or inventory system without modifying the wheel's code. - Daily Cooldown & Ad Spins: Includes a built-in free daily spin with a persistent 24-hour cooldown timer. Also supports a "watch ad" button to grant an extra spin.
- Customizable Animation & Audio: Fine-tune the spin duration and animation curve. Assign custom sounds for the spin, standard rewards, and rare rewards to enhance player feedback.
- Clean Public API: Simple, well-documented public methods (
SpinFree(),SpinOnAd(),ResetCooldown()) for easy integration with your UI buttons. - Self-Contained State: Automatically saves its own state (cooldown timer and ad watch status) using
PlayerPrefs, ensuring persistence across game sessions. - Reward Display: Shows a pop-up panel to celebrate the player's winnings, complete with a reward icon and amount.
This guide will walk you through setting up the Spin Wheel in your project.
- Find the
SpinWheelPanelprefab located inAssets/Spin Wheel/Prefabs/. - Drag and drop it into your scene hierarchy. It should be a child of a Canvas.
Select the SpinWheelPanel object in your scene and look at the Spin Wheel component in the Inspector. You will need to configure the following fields:
- UI References: Assign the required UI components. Most are already pre-assigned in the prefab.
Wheel Rect Transform: TheRectTransformof the spinning wheel image.Result Text: ATextMeshProUGUIelement to display cooldown timers and win messages.Spin Button: The button for the free daily spin.Watch Ad Button: The button to spin after watching an ad.Close Button: The button to close the spin wheel panel.
- Reward Display Panel: Configure the pop-up that appears after a spin.
Reward Display Panel: The parentGameObjectof the panel.Reward Amount Text: ATextMeshProUGUIto show the amount won.Reward Image: AnImagecomponent to show the icon of the reward (coin or gem).
- Spinning Settings:
Spin Duration: How long the wheel spins in seconds (e.g.,3.0).
- Rewards:
Coin Image,Gem Image: Sprites for your two currency types.Rewards: An array of 8RewardDataelements, corresponding to the 8 segments on the wheel.
- Probability Settings:
Probability Multiplier: A global multiplier to adjust the weight distribution. Keep at1for standard behavior.
- Audio:
Audio Source: TheAudioSourceused to play sounds.Spin Sound: Played when the wheel starts spinning.Reward Sound: Played for common rewards.Rare Reward Sound: A special sound for rewards marked asRareor higher.
- Animation:
Spin Curve: AnAnimationCurveto control the easing of the spin animation (e.g., EaseInOut).
The Rewards array has 8 elements, representing the 8 slices of the wheel. The order is important:
- Element 0: Top segment
- Element 1: Top-right segment
- Element 2: Right segment
- ...and so on, clockwise.
For each element, you must set:
- Name: The display name of the reward (e.g., "1,000 Coins").
- Amount: The currency amount to award.
doubleis used to support large numbers. - Type:
Coins(regular currency) orGems(premium currency). - Weight: The probability weight. Higher values are more common relative to other weights.
- Rarity:
Common,Uncommon,Rare, etc. Rewards marked asRareor higher will play therareRewardSound.
Connect your UI Button components' OnClick() events to the public methods in the SpinWheel.cs script:
- Free Spin Button: Connect to
SpinWheel.SpinFree(). - Watch Ad Button: Connect to
SpinWheel.SpinOnAd(). Note: You need to implement your ad provider's logic to call this method on ad completion. - Test/Reset Button (Optional): If you have a debug menu, connect a button to
SpinWheel.ResetCooldown()to reset the 24-hour timer.
The script automatically manages the interactability of these buttons based on the cooldown status.
The SpinWheel does not manage player currency directly. Instead, it fires a static C# event, OnRewardWon, when a spin is complete. You must create another script (e.g., a CurrencyManager) to listen for this event and award the currency to the player.
Here is an example of how to subscribe to the event:
// In your CurrencyManager.cs or a similar game management script
using UnityEngine;
public class CurrencyManager : MonoBehaviour
{
private void OnEnable()
{
// Subscribe to the event when this object is enabled
SpinWheel.OnRewardWon += HandleReward;
}
private void OnDisable()
{
// Unsubscribe to prevent memory leaks
SpinWheel.OnRewardWon -= HandleReward;
}
// This method will be called by the SpinWheel when a reward is won
private void HandleReward(double amount, RewardType type)
{
if (type == RewardType.Coins)
{
// Add 'amount' to the player's coin balance
Debug.Log($"Player won {amount} coins!");
// yourCoinVariable += amount;
}
else if (type == RewardType.Gems)
{
// Add 'amount' to the player's gem balance
Debug.Log($"Player won {amount} gems!");
// yourGemVariable += amount;
}
// Remember to save the player's new currency balance
// SavePlayerData();
}
}To make "5000 Coins" twice as likely to be won as "50 Gems":
- 5000 Coins Reward: Set
Weightto20. - 50 Gems Reward: Set
Weightto10.
The system automatically calculates the percentage chance based on the total weight of all 8 rewards.
- Download the latest release from the releases page.
- In Unity, go to
Assets > Import Package > Custom Package...and select the downloaded.unitypackagefile.
This project is licensed under the MIT License.
⭐ Star this repo if it helped you!
Made with ❤️ by Autech