I have a some game objects that are a unit away from the center. They are all contained in a parent object, see the image below.
When I rotate the parent object by 60°, the game objects individually rotate, as below.
Below is the script attached to the parent object that I use to rotate the parent object.
IEnumerator RotateSquaresParent(Vector3 byAngles, float duration)
{
Quaternion fromAngle = gameObject.transform.rotation ;
Quaternion toAngle = Quaternion.Euler (transform.eulerAngles);
toAngle = Quaternion.Euler (gameObject.transform.eulerAngles - byAngles);
for(float t = 0f ; t <= 1f ; t += Time.deltaTime/duration)
{
gameObject.transform.rotation = Quaternion.Lerp(fromAngle, toAngle, t) ;
yield return null ;
}
gameObject.transform.rotation = Quaternion.Lerp(fromAngle, toAngle, 1);
}
How can I rotate the parent object containing these square game objects without rotating them individually?
UPDATE
The squares represent enemy objects that would be shooting projectiles (yet to work on that) in my game. Thats why they'd have to be straight. As a player approaches a given child square (enemy), I would want to rotate individual child squares based on proximity and other conditions to possibly face the player object.