void Update() { if (Input.GetButtonDown("Fire1")) { Shoot(); audioManager.PlaySound("fireSound"); } void Shoot() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Gravity_One target = hit.transform.GetComponent <Gravity_One>(); if (target != null) { target.TakeDamage(damage); } } } }
void Update() { if (Input.GetButtonDown("Fire1") && Time.time > nextFire) { nextFire = Time.time + fireRate; Shoot(); } void Shoot() { RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Gravity_One target = hit.transform.GetComponent <Gravity_One>(); if (target != null) { target.TakeDamage(damage); } } } }