Nerd For Tech
Published in

Nerd For Tech

Slot Rotation Solution:2

Objective: Spin a Slot wheel

First of all create an item class that stores all the values that an item contains. Here, it contains a sprite and an value.

Create another script and define the list of items. Then create an Action event OnButtonClick which will send a signal to all the subscribers on events and finally create a bool variable which will allow spin only when the current spin stops.

Here, send a signal when the Spin method is called and spin is true. This method is connected to the spin button.

Then create a public method that returns an item sprite from the item list when int value is passed through parameter.

Now define a variable array to store all the images on the layout group then create a reference to the ItemDatabase script which stores the item list.

create three sprite variable to store the sprites during sprite change. Then create float variables for time and speed.

Now inside the Start, list all the children images in the itemSprites array and add the spinItem method as a subscriber to the event OnButtonClick.

Then call the GetSprite method which will the return a sprite at the I position and store it inside the image sprite.

Now create a method that subscribes to the event and inside it, set the spin speed and the spin time. Then call the Ienumerator function which will then start the spin.

Then in the Ienumerator, check if the spin time is remaining then create a condition to add value to the speed variable which will increase the wait time before next loop.

Then store the last sprite in a variable and assign it to temp which will then assign it to the first image in an array. Loop through the ItemImage while changing the sprite of the current image to the previous image and wait for speed time before going on a next while loop.

Finally set the Spin bool in ItemDatabase to true and allow the button to start next Spin.

And this is the final result.




NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium

Using Node-Red for testing

Storybook + Vue 3 + Typescript + Tsx + Vite

Continuous everything with Angular, Travis CI, Firebase and Greenkeeper

Immediately Invoked Function Expression (IIFE) in JavaScript .

How To Reduce App Development Cost Without Losing Out On Quality

How to convert your website into a web-app?

Object Oriented Javascript

$r, $0

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Niraj Karki

Niraj Karki

Unity Developer

More from Medium

Slot Rotation Solution:1

How to render Particle System OVER UI Canvas

Modular Design

Damage VFX Using Animated Sprites in Unity