Getting older elements of an Array/List and looping to the latest elements if index is less than zero
Hello,
I'm trying to figure out the logic for grabbing older elements of a List (array).
I have an array that stores a gameobject in repetition. For the sake of argument, let's say it stores a game object every frame for up to a total count of 7 frames. So the 7th frame is stored on array[6] and the 8th frame would overwrite the object at array[0].
How would I grab the 3rd and 6th oldest elements given the current index of the current element being written?
so say current index of the current frame is storing into index 2 (array[2]), the history would be index 1, 0, 6, 5, 4, 3. So how could I calculate that I would need array[6] and array[3]?
Answer by bamncan · Apr 13, 2020 at 01:07 AM
For now, I just had to create a switch statement since I haven't figured out an algebraic method to automatically do it yet:
int third = 0;
int sixth = 3;
switch (index) {
case 0:
third = 5; sixth = 2;
break;
case 1:
third = 6; sixth = 3;
break;
case 2:
third = 0; sixth = 4;
break;
case 3:
third = 1; sixth = 5;
break;
case 4:
third = 2; sixth = 6;
break;
case 5:
third = 3; sixth = 0;
break;
case 6:
third = 4; sixth = 1;
break;
}
Your answer
Follow this Question
Related Questions
Array of objects works half the time! 0 Answers
Unity freezes. I dont know why... 3 Answers