CircleSpawn
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CircleSpwan : MonoBehaviour
{
public Transform markerPrefab;[Range(1, 1000)] public int pointCount; //Amount of objects [Range(1, 1000)] public float radius; // Radius of object distance internal List markers;
[ContextMenu("StartProcess")]
public void StartProcess()
{
markers = new List<Transform>();
InitMarkers();
Makecircle();
}
public void Makecircle()
{
if (pointCount != markers.Count)
{
InitMarkers();
}
////// the core bit ///////
Quaternion quaternion = Quaternion.AngleAxis(360f / (float)(pointCount - 1), transform.up);
Vector3 vec3 = transform.forward * radius;
for (int index = 0; index < pointCount; ++index)
{
markers[index].position = transform.position + vec3;
markers[index].transform.parent = transform;
markers[index].transform.name = "Ingredient " + index;
// update for the next one
vec3 = quaternion * vec3;
}
////// end of the core bit ///////
}
private void InitMarkers()
{
if (pointCount > markers.Count)
{
for (int i = markers.Count; i < pointCount; i++)
{
// doesn't matter, we're updating the positions later
markers.Add(Instantiate(markerPrefab, Vector3.zero, Quaternion.identity) as Transform);
}
}
if (pointCount < markers.Count)
{
while (pointCount < markers.Count)
{
Destroy(markers[0].gameObject);
markers.RemoveAt(0); // dont miss this line out!!
}
}
}
}