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.

--

--

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