using UnityEngine;
using System.Collections;

public class FireProjectile4 : MonoBehaviour
{
	public GameObject effect;

	private float shotCounter;

	public float fireDelay = 10f;

	public float damageToGive;

	// Use this for initialization
	void Start ()
	{
		shotCounter = 5f;
	}

	// Update is called once per frame
	void Update()
	{
		if (shotCounter > 0f)
		{
			GetComponent<BoxCollider2D>().enabled = false;
			shotCounter -= Time.deltaTime;
		}

		if (shotCounter < 0f)
		{
			Instantiate(effect, transform.position, transform.rotation);
			GetComponent<BoxCollider2D>().enabled = true;
			shotCounter -= Time.deltaTime;
		}

		if (shotCounter < -3f)
		{
			shotCounter = fireDelay;
		}
	}

	void OnTriggerEnter2D(Collider2D other)
	{
		if (other.name == "Player 1")
		{
			other.GetComponent<PlayerHealth> ().giveDamage (damageToGive);
		}
	
		if (other.name == "Player 2")
		{
			other.GetComponent<PlayerHealth> ().giveDamage (damageToGive);
		}
	}
}
