Need Rect Transform Movement Tips

Hey Everyone!

Im trying to make a slot machine using canvas UI.

Not sure what they are called, but the 3 wheels that spin are composed of 2 sprites each. One on the top and one on the bottom. when the bottom sprite is no longer in view (Just below the slot window), it goes on top of the other sprite to simulate a never ending, spinning wheel.

To do this, I simply have an if statement that checks if the sprites transform.position.y is less than -420, and if so, then add 781 to its Y Position.

This was working great until I compiled it to my android (where the screen is smaller) that I found out a problem with this method.

When I change the size of my game window everything goes out of wack.

I think its because -420 is a different location when the screen is made smaller.

Also, I have the canvas set to scale with screen size, not sure if that has something to do with it

Can some smart person explain to me how can I overcome this problem?

EDIT:

At closer inspection, I see that when I change the size of the screen it doesnt detect its Y position on time, because step by step, i am able to see its passing -420

Probably the best way is to calculate that figure from your Screen Width or Height depending on which way the rect moves. I’ll assume height as that’s normal for a slot machine / fruit machine.

Find the height of the screen and see how much you have to divide the height by to get the correct values then use that division to place the items correctly. You may need to move anchors to the corners of each UI element to scale properly as well.

When the game starts on your phone it’ll get that screen height and scale the values by the division rather than a fixed value. You’ll need one for the too far away and another for the move to.

I needed to be using localPosition. I was only using position to alter my transform movement…