# Efficiency of moving references to gameobjects from and to lists

Hi there

Here is the problem I want to solve: around the camera there are, say, 27 cubes (3x3, with camera at the center) and I want the camera to always be at the center of this set, so once the camera moves out of the center cube I want redefine the new cube with camera as the center cube and move (as in move the transform) of the final row to the front row.

I can think of a few ways of doing this but I don’t know which would be more efficient computationally. Maybe someone can help me with that. The definition of the center cube can be just a flag.

This is what I have in mind, keeping the example in 2D for sake of argument. I have a 2d list of gameobjects cubes[n,n] in the correct order. So when camera moves past a certain point in x direction I do something like
temp=cubes[0,j]
cubes[0,j]=cubes[1,j]
cubes[1,j]=cubes[2,j]

cubes[N,j]=temp

Does this do what I think it does? I just want to move the references around, not make a deep copy, (I think I’m using that term right) so I don’t see why this should be a problem.

It feels like there should be a more elegant way though.

ok I came up with a possibly more elegant solution.

I check for the position of every cube, once the camera is a specific distance of cube c in a direction, it just moves it forward in that direction the necessary distance for it to be at the front. Doing this for all three dimensions should work the same way.

The difference is a distance check for each cube. But my intuition tells me this is cheaper than juggling lists.