I have spheres being instantiated as children of a GameObject. I want these spheres to follow the Position of the GameObject.
The trouble is, these spheres stubbornly stay in the place they were spawned in, and refuse to change their position upon any Transform position changes in Inspector during runtime.
spheres = new GameObject[mesh.vertexCount]; //create gameobject array, size of mesh vertex count
for (int i = 0; i < mesh.vertexCount; i++)
{
matrices1pos[i] = matrices1[i].position;
spheres[i] = Instantiate(spherePrefab, matrices1[i].position, Quaternion.identity);
spheres[i].transform.SetParent(GO2.transform);
}
I even tried adding code:
spheres[i].transform.localPosition = Vector3.zero;
but that doesn't make the spheres respond to parent's position changes either.
By the way, the location the Spheres spawn in is the location of the GameObject (called MeshChanger
) the script runs on. Changing the position of MeshChanger
transform during runtime has no effect either.
edit: Solved! see answer below
GO2
? Are you sure that it's not a reference to a prefab? – RuzihmMeshChanger.cs
I havepublic GO2 GO2;
before any functions, and for gameobjectGO2
I simply have script GO2.cs attached which sayspublic Transform Transform { get; set; }
– rashapouGO2
using the inspector? If so, make sure you are referring to a GO2 that is on a game object that is in the scene hierarchy. – Ruzihm