Last active
September 19, 2018 20:08
-
-
Save davepape/45d78a2a36ba34ed849718db14fb0eed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unity3d script to animate many circling objects | |
// Script creates the objects on startup, by instantiating a given object (create a prefab and assign it to the "obj" parameter in the inspector) | |
// Then moves them in a circle in the same way as circleChildren.cs | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class createCirclingChildren : MonoBehaviour { | |
public int numberOfChildren = 1; | |
public Object obj; | |
public float speed = 1f; | |
public float radius = 1f; | |
// Use this for initialization | |
void Start () { | |
for (int i=0; i < numberOfChildren; i++) | |
Instantiate(obj, transform); | |
} | |
// 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