Problem with intantiating arrays in script

So i have been working on my script and i have set the position of an array to another gameobject, but when i run my game , it is set not till the end of my canvas corner ( i have looked every object and they are set to 0 or on the right position) . I decided that i must use whole array to set that position , because i have have tried to set the parent object to that position before it must be instantiated and it was set not to 0 of that gameobject position.
Here’s the script:

           public GameObject[] cubes;
           public GameObject Cloness;
.....
        Camera mainCamera = GetComponent<Camera>();
        Cloness.transform.localPosition = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0));
        for (int y = 0; y < gridY; y++)
        {
            Vector3 pos = new Vector3(Cloness.transform.position.x, y, 0) * spacing;
            GameObject mySoundLine = Instantiate (prefab, pos, transform.rotation)as GameObject;
            mySoundLine.transform.parent = Cloness.transform;
        }
        cubes = GameObject.FindGameObjectsWithTag("cubes");

Thank you for the help already ^^

Could you try asking the question again? I wasn’t able to figure out what it is you need. Can you describe what exactly you are trying to accomplish?

Neither of these sentences makes any sense to me.

One piece of advice off the bat - I am guessing that, by the end of your code snippet, ‘cubes’ should contain all the things you just instantiated? If so, use this instead of FindObjectsWithTag:

cubes = new GameObject[gridY];
for (int y = 0; y < gridY; y++) {
GameObject mySoundLine = Instantiate(blah blah);
cubes[y] = mySoundLine;
}

It’s faster, the cubes will be in a predictable order in the array, and it won’t ever find stray tagged objects that might be laying around in the scene.

1 Like

What i really want to say is that i want to move my whole array with child object in another position ( it is in the corner of the screen ) and i don’t know how to do that . Without FindObjectsWithTag game is not working .