Пример #1
0
    void SimpleShoot()
    {
        timer = 0f;
        bool hitSuccess = false;
        int  whoHitted  = 0;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (powerActive == true && powerType == 2)
        {
            RaycastHit[] hits;
            hits = Physics.RaycastAll(shootRay, range, shootableMask);

            foreach (RaycastHit hit in hits.OrderBy(x => x.distance))
            {
                if (hit.collider.name == "Player " + otherNumber)
                {
                    PlayerHealth playerHealth = hit.collider.GetComponent <PlayerHealth>();
                    if (playerHealth != null && playerHealth.currentHealth > 0)
                    {
                        hitSuccess = true;
                        whoHitted  = 3;

                        LogManager.playerDamageMadePerSecond[playerNumber - 1] += damagePerShot;
                        LogManager.AddPlayerDamageMade(playerNumber, whoHitted, damagePerShot);
                        LogManager.AddPlayerDamageLog(otherNumber, whoHitted, damagePerShot);
                        playerHealth.TakeDamage(damagePerShot);
                    }
                }
                else
                {
                    EnemyHealth enemyHealth = hit.collider.GetComponent <EnemyHealth>();
                    if (enemyHealth != null)
                    {
                        hitSuccess = true;
                        whoHitted  = enemyHealth.type;

                        LogManager.playerDamageMadePerSecond[playerNumber - 1] += damagePerShot;
                        LogManager.AddPlayerDamageMade(playerNumber, whoHitted, damagePerShot);
                        // LogManager.enemiesShootedPerSecond[playerNumber]++;
                        enemyHealth.TakeDamage(damagePerShot, hit.point, playerNumber);
                    }
                }
            }
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
        else
        {
            if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
            {
                if (shootHit.collider.name == "Player " + otherNumber)
                {
                    PlayerHealth playerHealth = shootHit.collider.GetComponent <PlayerHealth>();
                    if (playerHealth != null && playerHealth.currentHealth > 0)
                    {
                        hitSuccess = true;
                        whoHitted  = 3;

                        LogManager.playerDamageMadePerSecond[playerNumber - 1] += damagePerShot;
                        LogManager.AddPlayerDamageMade(playerNumber, whoHitted, damagePerShot);
                        LogManager.AddPlayerDamageLog(otherNumber, 3, damagePerShot);
                        playerHealth.TakeDamage(damagePerShot);
                    }
                }
                else
                {
                    EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();
                    if (enemyHealth != null)
                    {
                        hitSuccess = true;
                        whoHitted  = enemyHealth.type;

                        LogManager.playerDamageMadePerSecond[playerNumber - 1] += damagePerShot;
                        LogManager.AddPlayerDamageMade(playerNumber, whoHitted, damagePerShot);
                        // LogManager.enemiesShootedPerSecond[playerNumber]++;
                        enemyHealth.TakeDamage(damagePerShot, shootHit.point, playerNumber);
                    }
                }

                gunLine.SetPosition(1, shootHit.point);
            }
            else
            {
                gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
            }
        }
        if (hitSuccess)
        {
            LogManager.AddPlayerShootLog(playerNumber, 1);
            LogManager.playerHittedPerSecond[playerNumber - 1]++;
        }
        else
        {
            LogManager.AddPlayerShootLog(playerNumber, 0);
        }

        LogManager.playerShootPerSecond[playerNumber - 1]++;
    }