using UnityEngine;
using System.Collections;

[RequireComponent(typeof(BulletFXPool))]
public class GunFX : MonoBehaviour  {
	
	public Transform shotPoint;
	public float shoot_interval=0.3f;
	BulletFXPool bulletPool;
	AircraftController ac;
	
	void Start() {
		bulletPool = GetComponent<BulletFXPool>();
		ac = GetComponent<AircraftController>();
	}
	
	public void Fire() {
		GameObject b = bulletPool.Get ();
		b.transform.position = shotPoint.position;
		BulletFX b_script = b.GetComponent<BulletFX>();
		b_script.direction = shotPoint.forward;
	}
	
	float shoot_timer;
	void Update() {
		shoot_timer+= Time.deltaTime;
		ac.shooting = false;
		if (Input.GetMouseButton(0) && ac.started && shoot_timer >= shoot_interval ) {
			Fire ();
			shoot_timer = 0;
			ac.shooting = true;
		}
	}
}

