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

public class RandomizeStars : MonoBehaviour
{
    public float timer;
    public GameObject[] stars;

    private float timerCounter = 0;


    // Update is called once per frame
    void Update()
    {
        if (timerCounter <= 0) {
            CreateRandomStar();
            timerCounter = timer;
        }
        else 
        {
            timerCounter -= Time.deltaTime;
        }
    }

    private void CreateRandomStar() 
    {
        System.Random r = new System.Random();
        int randomInt = r.Next(0, stars.Length);
        int randomHeight = r.Next(-300, 300);
        int randomLength = r.Next(-600, 600);
        GameObject star = stars[randomInt];
        GameObject initStar = Instantiate(star, new Vector3(randomLength, randomHeight,0), Quaternion.identity);
        initStar.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform, false);
    }

}
