How do I pass a reference?

If I'm accessing a GameObject via its Transform component, can I pass a reference to that component to a function and have the function access that GameObject?

Here's my script:

if (mapData.ContainsKey(xpos)) {
    neighbors[0] = (Transform)mapData[xpos];

Where `neighbors[]` is an array of Transforms. I'm trying to get transforms from the above hash into an array.

I'm trying to create a voxel terrain of cubes that each know what their neighbors are. Each cube originally knew its neighbors through raycasting, but that was to slow. So I tried another technique. When I generated the terrain, I created a hash of all the transforms, and gave that hash to each cube.

My function runs through the hash to see if it has anything near it in the "X Positive", that is, to the right, and if there is, sets `neighbors[0]` to equal the transform of that gameObject. It's obviously not working at the moment, but I have no idea why.

Yes. Transform is a class. You'd just do


If you are assigning mapDatg[xneg] = aTransform; it should work, because you access mapData[xneg] as a transform, so that with .gameObject should pull that out. If, on the other hand, you are assiging mapData[xneg] = aGameObject, then there is no GameObject.gameObject. Some code to look at might help.