Hi all. I’ve implemented an infinite scroll. I have a window in which only 3 out of 20 items are displayed. And this window is divided exactly into 3 parts for 3 elements. The problem I’m having is that it’s not possible to position the element at the end of the scroll exactly to the center of my element. That is, I would like to spin the vertical reel like in a casino, but in such a way that 3 elements would be precisely placed at the desired positions. How can this be implemented?
Directly manipulating the numeric position of UI elements is very difficult. The reason is because it is tightly tied to canvas render mode and scaling mode.
The way to success is to pre-make your UI with invisible “sentinel” objects that your program uses to decide positioning and spacing.
For instance, you might make a vertical pair of invisible GameObjects within the hierarchy, positioning them precisely at the spacing you want, then your script uses those positions as inputs to the computations of positions of all the other objects, something like:
// be sure you drag these in!
public Transform FirstCell;
public Transform SecondCell;
Then your index position for any given cell would be:
int whichCell = 123; // however you fill this out
Vector3 spacing = SecondCell.position - FirstCell.position;
// for each position of the regularly-spaced cells
Vector3 position = FirstCell.position + spacing * whichCell;
That works in any direction obviously.