using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeafSpawner : MonoBehaviour {
public float Radius = 3;
public float Rate = 5;
public LeafPhysics[] Leafs;
// Use this for initialization
void Start () {
}
private List<LeafPhysics> leaves = new List<LeafPhysics>();
private float time = 0;
// Update is called once per frame
void Update () {
float interval = 1 / Rate;
time += Time.deltaTime;
while (time > interval)
{
time -= interval;
Vector2 offset = Random.insideUnitCircle;
Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius);
LeafPhysics leaf = GameObject.Instantiate<LeafPhysics>(Leafs[Random.Range(0, Leafs.Length)]);
leaves.Add(leaf);
leaf.transform.position = point;
leaf.transform.rotation = Quaternion.Euler(new Vector3((Random.value - 0.5f) * 25, Random.value * 360, (Random.value - 0.5f) * 25));
float scale = Random.Range(0.9f, 1.3f);
leaf.transform.localScale = new Vector3(scale, scale, scale);
}
}
}