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

// Simple script to spawn a custom prefab object
public class SpawnGameObject : MonoBehaviour
{
    public GameObject prefab;

    [Range(0.1f,8f)]
    public float ratePerSecond = 1f;
    public bool randomRotation = false;
    public bool spawnAsChild = false;

    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(Spawn());
    }

    // Update is called once per frame
    void Update()
    {
        // transform.Rotate(new Vector3(0.2f,0.1f,0.4f));
    }

    IEnumerator Spawn(){
        while(true){

            //print("hi console");
            Quaternion rot = (randomRotation) ? Random.rotation : transform.rotation;
            // Quaternion rot = this.transform.rotation;

            Instantiate(prefab, transform.position, rot);
            
            // if(spawnAsChild)
            //     newObject.transform.parent = transform;

            yield return new WaitForSeconds(1f/ratePerSecond);
        }
        
    }
}
