using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MachineGun : MonoBehaviour
{
[SerializeField]
private float coolDown;
[SerializeField]
private GameObject bullet;
[SerializeField]
private float offset;
[SerializeField]
private float speed;
private float timer;
private void Start()
{
timer = coolDown;
}
public void Attack()
{
if (timer >= 0)
timer -= Time.deltaTime;
else
{
//Debug.Log("Shoot");
Vector3 dir = Vector3.Normalize(Input.mousePosition - new Vector3(Screen.width / 2, Screen.height / 2, 0));
GameObject temp = Instantiate(bullet, transform.position + (dir * offset), Quaternion.identity);
temp.GetComponent<Rigidbody>().velocity = dir * speed;
timer = coolDown;
}
}
}