Created
November 17, 2015 21:59
-
-
Save bdecarne/284d00a6508d73b573cc to your computer and use it in GitHub Desktop.
Unity : circle formation
This file contains 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
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