using UnityEngine;
using System.Collections;

public class ShootSingle : MonoBehaviour {

    public float FireInterval = 0.5f;
    public Transform ProjectilePrefab;
    public Transform FirePoint=null;
    public float AngleOffset = 0;
    public float PoliteWait = 1.5f;

    private float nextShot=-999f;
    private float startTime;

	void Start () {
        if(FirePoint==null)
            FirePoint = transform.FindChild("FirePoint");
        startTime = Time.fixedTime;
        nextShot = startTime + PoliteWait + ((PoliteWait==0)?0:FireInterval);
	}
	

	void Update () {
        if (Time.fixedTime - startTime < PoliteWait)
            return;

        if (!BoundsHelper.BoundsOK(transform, -1))
            return;

        if(Time.fixedTime >= nextShot)
        {
            Fire();
        }
	}

    private void Fire()
    {
        nextShot = Time.fixedTime + FireInterval;

        Transform proj = GameObject.Instantiate(ProjectilePrefab);
        proj.position = FirePoint.position;
        proj.localEulerAngles = transform.localEulerAngles + new Vector3(0,0, AngleOffset);
    }
}
