Nerd For Tech
Published in

Nerd For Tech

Slot Rotation Solution:3

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.

--

--

--

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 https://www.nerdfortech.org/.

Recommended from Medium

Events in Unity

The Fallacy of the “Full Stack” Web Developer

Try Hack Me: Basic Pentesting Write up

Introducing waPC

Introducing LASTEDIT(), a Timestamp Formula for Google Sheets

SLAE: Assignment 5.1

DevOps — Is it the right fit for your Organization?

LeetCode 10. Regular Expression Matching, Dynamic Programming Edition

DpTable

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

Organizing your UI for Performance in Unity

Creating background audio

Space Shooter 2D — Part 5

How to render Particle System OVER UI Canvas