using UnityEngine;
public class SMG : MonoBehaviour
{
public float damage = 10f;
public float Range = 80f;
//public float recoil = 30f
public float SMGfireRate = 45f;
private float nextTimeToFire = 0f;
public AudioSource SMGAudioSource;
[SerializeField] private AudioClip[] SMGfireSFX;
public Camera fpsCam;
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1") && Time.time >= nextTimeToFire)
{
nextTimeToFire = Time.time + 1f / SMGfireRate;
//recoil = transform.position(0f, 0f, 0f);
Shoot();
}
}
void Shoot()
{
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, Range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
}
SMGAudioSource.PlayOneShot(SMGfireSFX[Random.Range(0, SMGfireSFX.Length)]);
SMGAudioSource.PlayOneShot(SMGfireSFX[Random.Range(100, SMGfireSFX.Length)]);
}
}