예제 #1
0
    public void Shoot()
    {
        if (!canShoot)
        {
            return;
        }

        // Shoot cooldown
        canShoot = false;
        StartCoroutine(ShootCooldown());

        // Update ammo
        currentAmmo--;
        UpdateAmmoUI();

        // Play shoot sound
        audioSrc.clip = currentWeapon.shootSound;
        audioSrc.Play();

        // Check for enemy hit

        if (currentWeapon.ammoType == AmmoType.Projectile)
        {
            Instantiate(currentWeapon.projectile, transform.position, fpsCam.transform.rotation);
        }
        else
        {
            RaycastHit hit;
            if (Physics.Raycast(fpsCam.transform.position, transform.forward, out hit, currentWeapon.range))
            {
                // Debug.DrawRay(fpsCam.transform.position, hit.point, Color.green, 5f);
                if (hit.transform.gameObject.tag == "Enemy")
                {
                    crosshair.PlayDamageAnim();
                    hit.transform.gameObject.GetComponent <EnemyObject>().Hurt(currentWeapon.damage);
                }
            }
        }

        if (currentAmmo == 12 && !LevelMaster.reloadTutCompleted)
        {
            reloadTutorial?.ShowTutorial();
        }

        if (currentAmmo == 0)
        {
            canShoot = false;
            StartCoroutine(Reload());
            outOfAmmo = true;
        }
    }