﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponAutofire : MonoBehaviour {

	public GameObject bullet;
	public float reloadSpeed = 1;
	public float bulletSpeed = 10f;
	private float reloadTimer = 0;


	void Update () {

		reloadTimer += Time.deltaTime;

		if (reloadTimer >= reloadSpeed) 
		{
			reloadTimer = 0;
			Fire ();
		}
		
	}

	public void Fire()
	{
		GameObject newBullet = Instantiate (bullet, transform.position, Quaternion.identity);
		newBullet.GetComponent<Rigidbody2D> ().velocity = transform.right * bulletSpeed;
	}
}
