Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

getting element i+x from an array, looping through it

$
0
0
So, lets say I've got an array(a builtin array, but that doesn't really matter for the question) and I want to assign some values to the gameobjects in them. I get these values from another array, but the numbers may be shifted by x amount. So to assign the right values to the right objects I would need to shift the element I get by using something along the lines of: `array[i+x] = value[i];` Obviously doing something like this will leave the first x elements in array empty, and gives an index out of range on the last x elements. What I need to do to fix this is to check if i+x is higher than the length of array, and if so i should be 0. I think. Is there any elegant way of doing this?

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>