API ››
Parent Previous


public class PrizeWheel : MiniGame



RectTransform _Selector

Reference to the Selector Object. This is the object that points to the reward you will get and that also flaps as it collides with the wheel's knots.

eSelectorDirection _SelectorDirection

Where the selector is going to be attached (top, right, bottom, left)

bool _AnchorSelectorToCenter

True = selector it's on the center.   False will place it on the outside.

When in the center, the selector will not collide with the knots.

float _SelectorElasticDuration

Knots collide with the selector and rotate them. This variable represents how long it takes for the selector to return to the initial rotation.

float _SelectorElasticAmplitud

Higher values make the selector oscillate farther when returning to the initial orientation.

float _SelectorElasticPeriod

How many times, the selector will oscillate before resting.


Transform _Wheel

Reference to the Wheel Object. This object is rotated to spin the wheel.

float _Elements_Spread

Angular empty space between elements.Bigger values, increase the gap between elements.

float _Elements_Offset

Distance between the element and the wheel center. Positive values push elements to the outside

bool  _Elements_EqualDistribution

When false, Elements with higher Probability will get a wider section of the wheel.

If true, Probability is used for deciding in which element the wheel should end after spinning, but all elements get the same size regardless of their probability.


Transform _Knots

This is the root node of all Knots. All knots should be child of this object in the hierarchy.

Only enabled objects will be used as knots.

float _KnotsOffset

By default, knots are distributed around the wheel. This variable adds an offset to the first knot. So, if knots are placed every 30 degrees, and this value is set to 5 degrees. Then knots are placed at: 5, 35, 65, 95, etc.

This is useful to make knots aligned to the center of the elements instead to the beginning. Just add an offset equal to half the element angular size.

AudioClip[] _Sounds_KnotCollision

Every time the selector hit's a knot, it will pick a random AudioClip from this array and play it.

float _Sound_KnotCollision_MinVolume

To make the sounds more random, the volume can be random as well. So that even when the same audio clip is used, it will sound different.

volume = Random( Min_Volume, Max_Volume)

float _Sound_KnotCollision_MaxVolume

UnityEventAudioClip _PlayKnotSound

When a sound should be played, this callback is used. Normally it should be referencing the PlayOneShot function of an AudioSource.

However, if you are using a custom audio solution to play the sounds, this can be used to call your own functions.


bool _CenterOnElement

If true, when the wheel stops it will stop in the center of a reward.

bool _RotateSelector

Either rotates the Selector or rotate the Wheel while keeping the selector fixed.

float _Rotation_MinCycles

How many full laps it does every time it plays

float _Rotation_MaxCycles

Num_Rotations = Random( Min_Cycles, Max_Cycles )

float _Rotation_MinTime

How long it stays rotating

float _Rotation_MaxTime

How long will it take for the wheel to stop

float _SpeedUpTime

Total_Spin_time = Random( Min_Time, Max_Time )

float _Friction

When 0, the rotation will use a linear approach where it keeps a constant velocity. As this value gets higher, the rotation speed is slowly decreased until it stops. This creates an EasyOut effect.

Actually there is a fake small EasyIn, so the actual movement happens using an EasyInOut, where the In and Out have different weights.

UnityEvent _OnStartSpinning

Callback invoked when the wheel start spinning. Can be used for effects and triggering other custom game logic.

UnityEventInt _OnFinishSpinning

Callback to spawn effects and sounds when the wheel stops


float _TimeCollectReward

How long to wait once the wheel stops  to show the reward. This can be used to wait for sounds or effects to finish.

float _TimeNewRound

How long to wait before allowing the wheel to be spun again

Internal Variables

List<RectTransform> mKnots

List of all enabled knots found as children of _Knots

bool mIsPlaying

Is the wheel currently spinning?

float mSelectorMaxAngle

Maximum angle that can have a selector because of been pushed by a knot

float mWheelMaxAngleForKnot

Maximum angle at which the wheel can rotate and still a knot will be touching the selector.

float mSelectorElasticStartTime

This is used to update the selector flapping. It changes every time the selector looses touch of a knot

float mSelectorElasticStartAngle

Another variable to control the starting point of the flapping effect

int mForceReward

Index of the reward where the wheel is going to stop.


Public Methods

override void ApplyLayout()

Fills the mRewards and mKnots. Distributes the rewards around the wheel and places the Selector in the correct location.

override void FilterRewards()

Called right after mRewards is filled. This is used to remove any reward that doesn't make sense at that time according to gameplay and progression.

void ApplyLayout_Knots( float StartAngle )

Called from ApplyLayout, this distributes the knots around the wheel

void StartSpinning()

Starts the play. Computes the reward that should be selected and executes the DoPlay coroutine

void StartSpinning( int forceReward )

Once the reward is selected, this starts the DoPlay coroutine

override void StartRound()

Computes the reward that should be selected and calls StartSpinning to execute the DoPlay coroutine

void StopPlay()

Stops spinning the wheel

void GetRandomElement( ref int ElementIdx, out float Angle )

Selects a random reward based on their probabilities. Returns the angle at which the wheel should stop.

IEnumerator DoPlay( int TargetElementIdx, float ElementAngle )

Executes the spinning and then spinning back if the selector is not in the resting orientation

bool UpdateRotation(float initialAngle, float totalRotation, float initialTime, float totalTime, float speedUpTime)

Update the wheel rotation

bool UpdateSelector( ref int currentKnot, bool rotateback )

Updates the selector angle, detects collision against the knots

float GetElasticOut( float t, float a, float b, float amplitude, float period )

Easy In-Out with a short In and a long Out range

void GetSelectorAngles ()

Find selectorAngle: highest angle the selector reaches because of the knots

Created with the Personal Edition of HelpNDoc: Create help files for the Qt Help Framework