I have created an empty gameObject and added child gameObjects from primitives which I reference via a List<>
public class ObjectManager : MonoBehaviour { private List<GameObject> _cubes;
Primitive generation code snippet:-
for(int i = 0; i < cubesPerRow; i++)
{
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = new Vector3(nextX,nextY,0);
nextX = (cube.transform.localPosition.x + cube.transform.localScale.x) + cubeSpacing;
_cubes.Add(cube);
}
This works fine but now I wish to rotate the parent (objectManager) and have all the child cubes affected by this. To reiterate, I want to apply a single transform and have all of the objects move based on their parents transform.
When I apply a single transform to the parent via Update() none of the children move at all, however I can loop through the _cubes collection and apply transforms to them (which is not the desired behavior).
I am used to Flash's parent / child relationships but new to Unity and 3d so hopefully someone can explain the best way to work with Child objects to me going forward.
Thank you.
[EDIT: Here is my Update function]
void Update()
{
float amtToMove = 60.0f * Time.deltaTime;
transform.Rotate(amtToMove, amtToMove, amtToMove * 2);
}
I have also tried with gameObject.transform to no avail.