using UnityEngine;
using System.Collections;

public class FireProjectile32 : MonoBehaviour
{
	public GameObject projectile;

	public Controller2 player;

	public Transform launchPoint;

	private float shotCounter;

	public float fireDelay;

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

			shotCounter = 2f;
		}
	}

	// Update is called once per frame
	void Update()
	{
		if (FindObjectOfType<Controller2> () != null) 
		{
			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;
			}
		}
	}
}
