using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class newSpawnCube : MonoBehaviour
{
    public GameObject cube;
    public float spawnRadius = 5f;
    public int numberToSpawn = 10;
    public float spawnInterval = 1f;


    float lastTime = 0;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Time.time > lastTime + spawnInterval)
        {
            Spawn();
            lastTime = Time.time;
        }
    }

    void Spawn()
    {
        Vector3 pos = transform.position + Random.insideUnitSphere * spawnRadius;
        Quaternion rot = Random.rotation;
        GameObject obj = Instantiate(cube, pos, rot);
        obj.GetComponent<Renderer>().material.SetColor("_Color", Random.ColorHSV());
    }
}
