Exemplo n.º 1
0
    void HandleShoot(bool new_click)
    {
        //Telemetry
        if (gameObject.name == "Weapon_EyeLazers" || gameObject.name == "Weapon_MachineGun")
        {
        }
        else if (reloading)
        {
            if (new_click)
            {
                clicksBeforeFired++;
                dryfire.Play();
            }
            reloading = false;
            TelemetryLogger.LogClicksBeforeCanShoot(clicksBeforeFired, gameObject.name, GameObject.Find("Player").transform.position);
            clicksBeforeFired = -1;
            TelemetryLogger.LogShotWhileCooling(m_CurrentAmmo / maxAmmo, gameObject.name, GameObject.Find("Player").transform.position);
        }
        if (gameObject.name == "Weapon_Blaster(Clone)")
        {
            GameObject.Find("GameManager").GetComponent <GameFlowManager>().pistolShotsFired++;
        }
        else if (gameObject.name == "Weapon_Launcher(Clone)")
        {
            GameObject.Find("GameManager").GetComponent <GameFlowManager>().discShotsFired++;
        }
        else if (gameObject.name == "Weapon_Shotgun(Clone)")
        {
            GameObject.Find("GameManager").GetComponent <GameFlowManager>().shotgunShotsFired++;
        }
        else if (gameObject.name == "Weapon_BurstRifle(Clone)")
        {
            GameObject.Find("GameManager").GetComponent <GameFlowManager>().shotgunShotsFired++;
        }

        int bulletsPerShotFinal = shootType == WeaponShootType.Charge ? Mathf.CeilToInt(currentCharge * bulletsPerShot) : bulletsPerShot;

        // spawn all bullets with random direction
        for (int i = 0; i < bulletsPerShotFinal; i++)
        {
            Vector3        shotDirection = GetShotDirectionWithinSpread(weaponMuzzle);
            ProjectileBase newProjectile = Instantiate(projectilePrefab, weaponMuzzle.position, Quaternion.LookRotation(shotDirection));
            newProjectile.Shoot(this);
        }

        // muzzle flash
        if (muzzleFlashPrefab != null)
        {
            GameObject muzzleFlashInstance = Instantiate(muzzleFlashPrefab, weaponMuzzle.position, weaponMuzzle.rotation, weaponMuzzle.transform);
            // Unparent the muzzleFlashInstance
            if (unparentMuzzleFlash)
            {
                muzzleFlashInstance.transform.SetParent(null);
            }

            Destroy(muzzleFlashInstance, 2f);
        }

        m_LastTimeShot = Time.time;

        // play shoot SFX
        if (shootSFX && !useContinuousShootSound)
        {
            m_ShootAudioSource.PlayOneShot(shootSFX);
        }

        // Trigger attack animation if there is any
        if (weaponAnimator)
        {
            weaponAnimator.SetTrigger(k_AnimAttackParameter);
        }

        // Callback on shoot
        if (onShoot != null)
        {
            onShoot();
        }

        OnShootProcessed?.Invoke();
    }