Spawn added objects into a circle
well what im trying to do here is to put prefabs in a list then put them in a circle form on canvas but for some reason they are not being added on to the list here some of the code:
public class CreateCircle : MonoBehaviour {
public List<GameObject> points;
//int numObjects = 12;
// Use this for initialization
void Start ()
{
points = new List<GameObject>();
Vector3 center = transform.position;
for (int i = 0; i < points.Count; i++)
{
//points.Add(points[i]);
Vector3 pos = RandomCircle(center, 1.0f, Random.Range(0f,10f));
Instantiate(points[i], pos, Quaternion.identity);
Debug.Log(points.ToString());
}
}
Vector3 RandomCircle(Vector3 center, float radius, float a)
{
Debug.Log(a);
float ang = a;
Vector3 pos;
pos.x = center.x + radius * Mathf.Sin(ang * Mathf.Deg2Rad);
pos.y = center.y + radius * Mathf.Cos(ang * Mathf.Deg2Rad);
pos.z = center.z;
return pos;
}
Comment
Answer by doublemax · Oct 08, 2016 at 08:48 PM
public List<GameObject> points;
If this is a list that you fill with GameObjects through the editor, then the following line doesn't make sense, because it clears the list:
points = new List<GameObject>();
THAN$$anonymous$$S $$anonymous$$AN I$$anonymous$$ PRETTY SLEEPY AND I WAS SEARCHING FOR THAT AGAIN AND AGAIN NOW I $$anonymous$$NOW THAN$$anonymous$$S!