Skip to content

Instantly share code, notes, and snippets.

@davepape
Last active September 19, 2018 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davepape/d4f5b1e1b6789f9713ed1d0f58d11d66 to your computer and use it in GitHub Desktop.
Save davepape/d4f5b1e1b6789f9713ed1d0f58d11d66 to your computer and use it in GitHub Desktop.
// Unity3D script to move all the children of an object in a circle
// Uses "childCount" and "GetChild()" to access all the immediate child nodes
// Positions each on a circle, spreading them evenly around the circle
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class circleChildren : MonoBehaviour {
public float speed = 1f;
public float radius = 1f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
for (int i=0; i < transform.childCount; i++)
{
Transform child = transform.GetChild(i);
float angle = Time.time * speed + 2f*Mathf.PI*i/transform.childCount;
child.localPosition = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0f) * radius;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment