Think in a slot machine.
In one column, I got an array of X images (“Slide”, in the image below, has 3 elements as example). I got a window (a GUILayout). I want that the images of the array are shown in that window, then the image moves down, and the next image of the array moves in the window. I got that. The thing is that when I reach the end of the array, there’re no more images to show. I need to put back the 1st element of the array on the top of the last image. How can I do that??
I leave an image for better explanation.
Code:
Here the array has 13 elements. Only can be shown 3 elements at time (it’s a 3x5 slot machine, the image was illustrative, to get the idea).
function drawCol(col : int, movement :float)
{
var x : int = 0 + (col * images[0].width);
var y : float = 0;
var image : Texture2D;
GUILayout.BeginArea(Rect(slotX, slotY, images[0].width * 5, images[0].height * 3));
for(var i : int = 0; i < 13; i++)
{
if(oneTime == false)
{
// Fills the array with random symbols
var randomImage : int = Random.Range(0,images.length);
image = images[randomImage];
slotGrid[col,i] = randomImage;
}
else
{
image = images[slotGrid[col,i]]; //Gets the already stored symbols
}
// Sets y based on the height of the image (uses 0 index because all images must have the same size)
// rests images[0].height * 10 because if not, the slot grid is drawn from 0 to 1536. We need that is
// drawn from -1536 to 384 (slot grid area, where the Layout is)
y = images[0].height * i + movement - (images[0].height * 10);
if((y < images[0].height * 3) && (y >= slotY - images[0].height )) // Only draws a texture if it's in visible area
{
GUI.DrawTexture(Rect(x, y, image.width, image.height), image);
}
}
GUILayout.EndArea();
}