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

public class PowerUps : MonoBehaviour {

    public GameObject[] powerUps;

    public Transform spawnPoints;

    private float timeToSpawn;
    private float timeToSpawnNext;
    private float timer;

	void Start () {
        timeToSpawn = Random.Range(0f, 100f);
        timeToSpawnNext = Random.Range(0f, 100f);
        timer = Time.time;
	}
	
	void Update () {
        float t = Time.time - timer;

        if (t >= timeToSpawn) {
            transform.position = new Vector3(spawnPoints.position.x, spawnPoints.position.y);
            Quaternion spawnRotation = Quaternion.identity;
            int randomNumber = Random.Range(0, 3);

            Instantiate(powerUps[randomNumber], transform.position, spawnRotation);
        }

        timeToSpawn = Time.time + timeToSpawnNext;
	}
}
