Slot Rotation Solution:3

Niraj Karki
Nerd For Tech
Published in
3 min readApr 1, 2022

--

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. Then create two float variables to compare time.

Here, send a signal to subscribers when the Spin method is called and spin is true. This method is connected to the spin button. Also store the current time and create a stop time value.

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

create a method which returns bool when the current time reaches the stop time.

Create a float variable for speed and then a transform position variables to store the position for destination when the items reaches bottom. give these item an Id to define their sprites. Then create a reference variable for ItemDatabase Script and a gameobject variable for the object the items in a single reel are child to. Then finally a bool variable to allow the slow spin at the end.

Then inside the start, assign the parent object to variable and list all the script component of its child(items) to the array.

Now add the MoveItem method as a subscriber to OnButtonClick event and finally assign the sprite to the item according to its item Id.

When the method receives the signal, set the speed of rotation to random.

Then set the speed of all the items in the same parent object to a same random speed.

Now create a behavior for the reel to spin when button is presses and when the item position reaches the bottom position, change the position to the top.

Then when the spin time is finished, slow down the spin and stop it after the speed is lower than 0.

This is the Hierarchy.

This is the script connected to the items.

And this is the final result.

--

--