Nerd For Tech
Published in

Nerd For Tech

Slot Rotation Solution:1

Objective: Spin a Slot wheel

First of all create a group of items and place it under an empty gameobject.

Then add Vertical layout group to the empty gameobject and add a behaviour script which will then rotate the items.

Now create a Vector3 variable which will store the default position(position at the start) of the item group. Then create a speed variable which will define the rotation speed of the items. Then create a float variable that will store the current time and the target time which will then stop the spin.

Now inside the start, define the default position to the local position of the layout group.

Now define a method which will be used by either button or events to start the spin. Here, we define the speed of spin and also define the amount of seconds to spin before stopping then call an Ienumerator function which will handles the spin loop.

And finally inside a Ienumerator function, we loop using While loop which checks for time and will stop after the time reaches the target amount of seconds. After reaching certain amount of seconds, we slow down the speed of spin. Then we move the layout group downwards until it reaches a certain position where the layout group jumps back to its default position and move downwards continuously.

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