Skip to content

Instantly share code, notes, and snippets.

@bdecarne
Created November 17, 2015 21:59
Show Gist options
  • Save bdecarne/284d00a6508d73b573cc to your computer and use it in GitHub Desktop.
Save bdecarne/284d00a6508d73b573cc to your computer and use it in GitHub Desktop.
Unity : circle formation
using UnityEngine;
using System.Collections;
public class TestScript : MonoBehaviour {
public GameObject obj;
private int points;
private double radius;
private Vector3 center;
// Use this for initialization
void Start () {
points = 20;
radius = 10;
center = new Vector3(0, 0, 0);
float slice = 2 * Mathf.PI / points;
for (int i=0; i< points; i++)
{
float angle = slice * i;
int newX = (int)(center.x + radius * Mathf.Cos(angle));
int newZ = (int)(center.z + radius * Mathf.Sin(angle));
GameObject clone = (GameObject) Instantiate(obj, new Vector3(newX, 0, newZ), Quaternion.identity);
}
}
// Update is called once per frame
void Update () {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment