public void Shoot() { if (timer >= timeBetweenBullets && weaponBehavior.CanIShoot()) { if (unitAmmoCount > 0) { unitAmmoCount--; timer = 0f; reloadTimer = 0; // Enable gunLine, gunLight and Play gunAudio. PlayEffects(); } else if (reloadTimer >= timerBetweenReload) { Reloading(); } } }
public void Shoot() { if (timer >= timeBetweenBullets && weaponBehavior.CanIShoot()) { if (unitAmmoCount > 0) { unitAmmoCount--; timer = 0f; reloadTimer = 0; // Enable gunLine, gunLight and Play gunAudio. PlayEffects(); gunLine.SetPosition(0, shotOutPoint.transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = shotOutPoint.transform.position; shootRay.direction = shotOutPoint.transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { Hero hero = shootHit.collider.GetComponent <Hero> (); hero.TakeDemage(); gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } } else if (reloadTimer >= timerBetweenReload) { Reloading(); } } }