﻿using UnityEngine;
using System.Collections;

public class StarSpawner : MonoBehaviour {

	public float secondsPerStar;
	public GameObject fallingStarPrefab;

	private float timer;
	// Use this for initialization
	void Start () {
		timer = 0f;
	}
	
	// Update is called once per frame
	void Update () {
		if (TimeForManna()) {
			SpawnManna ();
		}
		timer += Time.deltaTime;
	}

	bool TimeForManna (){
		if (timer > secondsPerStar) {
			return true;
		} else {
			return false;
		}
	}

	void SpawnManna(){
		GameObject newStar = Instantiate (fallingStarPrefab) as GameObject;
		newStar.transform.parent = gameObject.transform;
		newStar.transform.position = gameObject.transform.position;
		newStar.transform.Translate (Vector3.right *Random.Range (0f, 8f));
		timer = 0;
	}
}
