Changing position of Prefabs

Hello everyone, I am writing a code in which I need to show different objects one at a time, at the push of a button, in the same position, I am having troubles in the latter part. With my code I am able to show the objects one at a time, but they ignore the part in which I fixed a position for each one of them. This code used to work perfectly for other objects, while it does not work with my new objects, could it be that there is a different code for prefab objects? The objects I am using now are basically different cubes stuck together in a prefab in order to form different shapes. I will paste here my code, please let me know if you need anything else. Thank you very much in advance!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class show_one : MonoBehaviour
{
    public GameObject[] array = new GameObject[16];
    // Start is called before the first frame update
    void Start()
    {
        for (int i=1; i<array.Length; i++)
        {
            array*.SetActive(false);*

}
}

// Update is called once per frame
void Update()
{
Vector3 pos = new Vector3(0,0,0);
for (int i = 0; i<array.Length; i++)
{
array*.transform.Translate(pos);*
}
}
int currentActiveObjectIndex = 0;
public void whenButtonClicked()
{
currentActiveObjectIndex++;
UpdateCurrentlyActiveObject();
}
private void UpdateCurrentlyActiveObject()
{
for (int i=0; i<array.Length; i++)
{
array*.SetActive(i==currentActiveObjectIndex);*
}
}
}

I can see two things in your code that are slightly strange.

Line 21 creates a zero Vector 3 and you are using that in line 24 to translate. Translate moves from the current position by the given amount and, since the given amount is zero, all elements are moving by zero, which is probably not what you meant.

The second thing is that you are doing this in Update, which means that you are doing exactly the same thing every frame - moving them by zero.

To answer your question about prefabs behaving differently, the answer is no. When you instantiate a Prefab, its behaviour (in terms of moving it) is no different from any other game object. They move in world space or local space, depending on the methods you call just as do any game objects.

Do let us know what you think about the comments above…

Okay, so given the information we now have i assume that the following is the issue here:

You have your objects L1-LXX. For now we do not care if they are prefabs or not.
Those have a global position. But all those objects are empty transforms. They do not actually show anything at this position.

Now the actual visuals are on the level beneath right? So in under the top transform there are your “Cubes”. They have a position as well, which will always be in exact relation to the top transform.

If you click on one of the cubes and look into the inspector your will see the local coordinates of an object. So its relative position in regards to the parent transform. This means that if i have a top transform L123 at position (1,0,0) and a child cube that shows the position (100,100,100) in the inspector, then setting the position of L123 to (0,0,0) will move the cube that you can see, but in global coordinates it will be seen on position (100, 100, 100). At position (0,0,0) there is only an empty transform.

Which brings us to your issue. When you look at picture 1 of your merged image then we can see that the local position of one of your blocks is almost (10,10) away from the center of your parent transform (remember: inspector shows local position) This means that if you set the position to (0,0,0) your actual visuals will be in some other position.

So what you have to do is to make sure that your child transforms are actually close to your parent transform. That is all it needs. (probably)