using UnityEngine;
using System.Collections;

public class FireProjectile22 : MonoBehaviour
{
	public GameObject projectile;

	public Controller2 player;

	public Transform launchPoint;

	private float shotCounter;

	public float fireDelay;

	private float startTime;

	// Use this for initialization
	void Start ()
	{
		if (FindObjectOfType<Controller2> () != null)
		{
			player = FindObjectOfType<Controller2> ();

			startTime = Time.time;

			shotCounter = 0.1f;
		}
	}

	// Update is called once per frame
	void Update()
	{
		if (FindObjectOfType<Controller2> () != null)
		{
			// Over time, the fire rate increases.
			if ((Time.time - startTime) > 30f)
			{
				fireDelay = 2f;
			}

			if ((Time.time - startTime) > 60f)
			{
				fireDelay = 1.66f;
			}

			if ((Time.time - startTime) > 120f)
			{
				fireDelay = 1.33f;
			}

			if ((Time.time - startTime) > 180f)
			{
				fireDelay = 1f;
			}
			shotCounter -= Time.deltaTime;

			if (player.transform.position.x > transform.position.x && shotCounter < 0)
			{
				Instantiate (projectile, launchPoint.position, launchPoint.rotation);
				shotCounter = fireDelay;
			}

			if (player.transform.position.x < transform.position.x && shotCounter < 0)
			{
				Instantiate (projectile, launchPoint.position, launchPoint.rotation);
				shotCounter = fireDelay;
			}
		}
	}
}
