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

public class Spawn : MonoBehaviour {

	public GameObject barreiraPrefab;
	public GameObject rochaPrefab;
	public GameObject pedraPrefab;
	public GameObject planoPrefab;
	public GameObject curvaRochaPrefab;
	public GameObject redondaRochaPrefab;
	GameObject tempPrefab;
	public float rateSpawn;
	public float currentTime;
	private int posicao;
	private float y;

	// Use this for initialization
	void Start () {
		currentTime = 0;
	}
	
	// Update is called once per frame
	void Update () {
		currentTime += Time.deltaTime;


		if (currentTime >= rateSpawn) {
			currentTime = rateSpawn;
			posicao = Random.Range (1, 60);


			if (posicao < 11) {
				y = -3.15f;
				tempPrefab = Instantiate (barreiraPrefab) as GameObject;
			}
			if (posicao > 10 && posicao < 20) {
				y = -3.15f;
				tempPrefab = Instantiate (pedraPrefab) as GameObject;
			}
			if (posicao > 20 && posicao < 30) {
				y = -3.15f;
				tempPrefab = Instantiate (rochaPrefab) as GameObject;
			}
			if (posicao > 30 && posicao < 40) {
				y = -3.15f;
				tempPrefab = Instantiate (curvaRochaPrefab) as GameObject;
			}
			if (posicao > 40 && posicao < 50) {
				y = -3.15f;
				tempPrefab = Instantiate (redondaRochaPrefab) as GameObject;
			}
			if (posicao > 50 && posicao < 60) {
				y = -3.15f;
				tempPrefab = Instantiate (planoPrefab) as GameObject;
			}
				
			tempPrefab.transform.position = new Vector3 (transform.position.x,y, tempPrefab.transform.position.z);
			rateSpawn += 1;
		}
	}
}
