using System.Collections;
using UnityEngine;
using matnesis.TeaTime;

public class PlayerShoot : MonoBehaviour 
{
	public GameObject bullet;
	public float rechargeDelay = 2.5f;
	public Transform shotgunHole;
	public int spentBullets;

	private TeaTime recharge;

	// Use this for initialization
	void Start () 
	{
		recharge = this.tt().Add(rechargeDelay, () =>
			{
				spentBullets = 0;
			}).Immutable();
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(Input.GetButtonDown(Buttons.Shoot) && spentBullets < GameManager.bulletCap)
		{	
			recharge.Stop ();
			GameObject bulletInstantiate = (GameObject)Instantiate (bullet, shotgunHole.position, bullet.transform.rotation);
			spentBullets++;
		}
		if(Input.GetButtonUp(Buttons.Shoot))
		{
			recharge.Play ().Forward ();
		}
	}
}
