コード例 #1
0
ファイル: WeaponBase.cs プロジェクト: nprsd/ZombiesByNP
    void Fire()
    {
        if (fireTimer < fireRate || !isEnabled)
        {
            return;
        }

        if (loadedBullets <= 0)
        {
            StartCoroutine(DisableFire());
            soundManager.Play(drySound);
            return;
        }

        RaycastHit hit;

        for (int i = 0; i < pellets; i++)
        {
            if (Physics.Raycast(shootPoint.position, CalculateSpread(spread, shootPoint), out hit, range))
            {
                HealthManager health = hit.transform.GetComponent <HealthManager>();

                if (health)
                {
                    health.ApplyDamage(GetWeaponDamage());

                    if (health.IsDead)
                    {
                        KillReward killReward;

                        if (health.referer)
                        {
                            killReward = health.referer.transform.GetComponent <KillReward>();
                        }
                        else
                        {
                            killReward = hit.transform.GetComponent <KillReward>();
                        }

                        if (killReward)
                        {
                            int exp  = killReward.exp;
                            int fund = killReward.fund;

                            levelSystem.GiveExp(exp);
                            fundSystem.AddFund(fund);

                            rewardText.Show(exp, fund);
                        }
                    }

                    EnemyType enemyType = hit.transform.GetComponent <EnemyType>();

                    if (enemyType)
                    {
                        if (enemyType.type == Type.BIO)
                        {
                            CreateBlood(hit.point, hit.normal);
                        }
                    }
                    else
                    {
                        CreateRicochet(hit.point, hit.normal);
                    }
                }
                else
                {
                    CreateRicochet(hit.point, hit.normal);

                    if (hit.transform.tag == "bounds")
                    {
                        Debug.Log("Hit Wall");
                    }
                    if (hit.transform.tag == "wood")
                    {
                        CreateWood(hit.point, hit.normal);
                    }
                    if (hit.transform.tag == "metal")
                    {
                        CreateMetal(hit.point, hit.normal);
                    }
                    if (hit.transform.tag == "ground")
                    {
                        CreateSand(hit.point, hit.normal);
                    }
                    if (hit.transform.tag == "stone")
                    {
                        CreateStone(hit.point, hit.normal);
                    }
                    if (hit.transform.tag == "alien")
                    {
                        EasterEgg.counter += 1;
                        print(EasterEgg.counter);
                        hit.transform.gameObject.GetComponent <AlienScript>().deathAnim();
                        soundManager.Play(laugh);
                        if (EasterEgg.isComplete)
                        {
                            print("Easter egg complete");
                        }
                    }
                    if (hit.transform.tag == "tank")
                    {
                        CreateWater(hit.point, hit.normal);
                        GameObject bulletHole = Instantiate(bulletImpact, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));
                        bulletHole.transform.SetParent(hit.transform);
                        Destroy(bulletHole, 10f);
                    }
                }
            }
        }

        if (hasLastFire && loadedBullets <= 1)
        {
            animator.CrossFadeInFixedTime("FPSHand|FireLast", 0.01f);
        }
        else
        {
            animator.CrossFadeInFixedTime("FPSHand|Fire", 0.01f);
        }

        GameObject gunSmokeEffect = Instantiate(gunSmoke, muzzlePoint.position, muzzlePoint.rotation);

        Destroy(gunSmokeEffect, 5f);

        GiveRecoil();

        muzzleflash.Play();
        soundManager.Play(gunFireSound);

        loadedBullets--;
        UpdateAmmoText();

        fireTimer = 0.0f;
    }
コード例 #2
0
    void Fire()
    {
        if (fireTimer < fireRate || !isEnabled)
        {
            return;
        }

        fireTimer = 0f;                 // Reset timer

        if (loadedBullets <= 0)
        {
            // When Ammo is out, make fire is not working for a moment
            StartCoroutine(DisableFire());
            soundManager.Play(drySound);
            return;
        }

        RaycastHit hit;

        for (int i = 0; i < pellets; i++)
        {
            if (Physics.Raycast(shootPoint.position, CalculateSpread(spread, shootPoint), out hit, range))
            {
                HealthManager health = hit.transform.GetComponent <HealthManager>();

                if (hit.transform.tag == "Player")
                {
                    CreateRicochet(hit.point, hit.normal);
                }
                else if (health)
                {
                    bool wasDead = health.IsDead;
                    health.ApplyDamage(GetWeaponDamage());

                    if (!wasDead && health.IsDead)
                    {
                        KillReward killReward;

                        // Check it was head
                        if (health.referer)
                        {
                            killReward = health.referer.transform.GetComponent <KillReward>();
                        }
                        else
                        {
                            killReward = hit.transform.GetComponent <KillReward>();
                        }

                        if (killReward)
                        {
                            int   exp         = killReward.exp;
                            int   fund        = killReward.fund;
                            int   playerCount = PhotonNetwork.playerList.Length;
                            float bonusExp    = exp * 0.3f;
                            float bonusFund   = fund * 0.4f;

                            exp  += ((int)bonusExp * (playerCount - 1));
                            fund += ((int)bonusFund * (playerCount - 1));

                            levelSystem.GiveExp(exp);
                            fundSystem.AddFund(fund);

                            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

                            foreach (GameObject player in players)
                            {
                                if (player == gameObject.transform.root.gameObject)
                                {
                                    continue;
                                }

                                player.GetComponent <FundSystem>().AddBonus((int)bonusExp, (int)bonusFund);
                            }

                            rewardText.Show(exp, fund);

                            // Update player status
                            string weaponName = transform.name;

                            switch (weaponName)
                            {
                            case "Glock":
                                playerStatus.killsGlock++;
                                break;

                            case "MP5K":
                                playerStatus.killsMp5k++;
                                break;

                            case "UMP45":
                                playerStatus.killsUmp45++;
                                break;

                            case "Python":
                                playerStatus.killsPython++;
                                break;

                            case "M870":
                                playerStatus.killsM870++;
                                break;

                            case "AKM":
                                playerStatus.killsAkm++;
                                break;
                            }

                            playerStatus.totalKills++;
                        }
                    }

                    EnemyType enemyType = hit.transform.GetComponent <EnemyType>();

                    if (enemyType)
                    {
                        if (enemyType.type == HitType.BIO)
                        {
                            CreateBlood(hit.point, hit.transform.rotation);
                        }
                    }
                    else
                    {
                        CreateRicochet(hit.point, hit.normal);
                    }
                }
                else
                {
                    CreateRicochet(hit.point, hit.normal);
                    CreateBulletHole(hit.point, hit.normal, hit.transform);
                }
            }
        }

        if (hasLastFire && loadedBullets <= 1)
        {
            animator.CrossFadeInFixedTime("FPSHand|FireLast", 0.01f);
        }
        else
        {
            animator.CrossFadeInFixedTime("FPSHand|Fire", 0.01f);
        }

        networkPlayer.FireWeapon();

        GameObject gunSmokeEffect = Instantiate(gunSmoke, muzzlePoint.position, muzzlePoint.rotation);

        Destroy(gunSmokeEffect, 5f);

        GiveRecoil();

        muzzleflash.Play();
        soundManager.Play(gunFireSound);

        loadedBullets--;
        UpdateAmmoText();

        fireTimer = 0.0f;
    }
コード例 #3
0
    void Fire()
    {
        if (!canShoot)
        {
            return;
        }

        if (loadedBullets <= 0)
        {
            // When Ammo is out, make fire is not working for a moment
            StartCoroutine(DisableFire());
            soundManager.Play(drySound);

            canShoot = false;
            StartCoroutine(CoResetShootable());
            return;
        }

        RaycastHit hit;

        for (int i = 0; i < pellets; i++)
        {
            if (Physics.Raycast(shootPoint.position, CalculateSpread(spread, shootPoint), out hit, range))
            {
                HealthManager health = hit.transform.GetComponent <HealthManager>();

                if (hit.transform.tag == "Player")
                {
                    CreateRicochet(hit.point, hit.normal);
                }
                else if (health)
                {
                    bool wasDead = health.IsDead;
                    health.ApplyDamage(GetWeaponDamage());

                    if (!wasDead && health.IsDead)
                    {
                        KillReward killReward;

                        // Check it was head
                        if (health.referer)
                        {
                            killReward = health.referer.transform.GetComponent <KillReward>();
                        }
                        else
                        {
                            killReward = hit.transform.GetComponent <KillReward>();
                        }

                        if (killReward)
                        {
                            int exp  = killReward.exp;
                            int fund = killReward.fund;

                            fundSystem.AddFund(fund);
                            rewardText.Show(exp, fund);
                        }
                    }

                    EnemyType enemyType = hit.transform.GetComponent <EnemyType>();

                    if (enemyType)
                    {
                        if (enemyType.type == HitType.BIO)
                        {
                            CreateBlood(hit.point, hit.transform.rotation);
                        }
                    }
                    else
                    {
                        CreateRicochet(hit.point, hit.normal);
                    }
                }
                else
                {
                    CreateRicochet(hit.point, hit.normal);
                    CreateBulletHole(hit.point, hit.normal, hit.transform);
                }
            }
        }

        if (hasLastFire && loadedBullets <= 1)
        {
            animator.CrossFadeInFixedTime("FPSHand|FireLast", 0.01f);
        }
        else
        {
            animator.CrossFadeInFixedTime("FPSHand|Fire", 0.01f);
        }

        GameObject gunSmokeEffect = Instantiate(gunSmoke, muzzlePoint.position, muzzlePoint.rotation);

        Destroy(gunSmokeEffect, 5f);

        GiveRecoil();

        muzzleflash.Play();
        soundManager.Play(gunFireSound);

        loadedBullets--;
        UpdateAmmoText();

        canShoot = false;
        StartCoroutine(CoResetShootable());
    }
コード例 #4
0
    void Fire()
    {
        if (fireTimer < fireRate || !isEnabled)
        {
            return;
        }

        if (loadedBullets <= 0)
        {
            // When Ammo is out, make fire is not working for a moment
            StartCoroutine(DisableFire());
            soundManager.Play(drySound);
            return;
        }

        RaycastHit hit;

        for (int i = 0; i < pellets; i++)
        {
            if (Physics.Raycast(shootPoint.position, CalculateSpread(spread, shootPoint), out hit, range))
            {
                HealthManager health = hit.transform.GetComponent <HealthManager>();

                if (health)
                {
                    health.ApplyDamage(GetWeaponDamage());

                    if (health.IsDead)
                    {
                        KillReward killReward;

                        // Check it was head
                        if (health.referer)
                        {
                            killReward = health.referer.transform.GetComponent <KillReward>();
                        }
                        else
                        {
                            killReward = hit.transform.GetComponent <KillReward>();
                        }

                        if (killReward)
                        {
                            int exp  = killReward.exp;
                            int fund = killReward.fund;

                            levelSystem.GiveExp(exp);
                            fundSystem.AddFund(fund);

                            rewardText.Show(exp, fund);
                        }
                    }

                    EnemyType enemyType = hit.transform.GetComponent <EnemyType>();

                    if (enemyType)
                    {
                        if (enemyType.type == Type.BIO)
                        {
                            CreateBlood(hit.point);
                        }
                    }
                    else
                    {
                        CreateRicochet(hit.point, hit.normal);
                    }
                }
                else
                {
                    CreateRicochet(hit.point, hit.normal);

                    GameObject bulletHole = Instantiate(bulletImpact, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));
                    bulletHole.transform.SetParent(hit.transform);
                    Destroy(bulletHole, 10f);
                }
            }
        }

        if (hasLastFire && loadedBullets <= 1)
        {
            animator.CrossFadeInFixedTime("FPSHand|FireLast", 0.01f);
        }
        else
        {
            animator.CrossFadeInFixedTime("FPSHand|Fire", 0.01f);
        }

        GameObject gunSmokeEffect = Instantiate(gunSmoke, muzzlePoint.position, muzzlePoint.rotation);

        Destroy(gunSmokeEffect, 5f);

        GiveRecoil();

        muzzleflash.Play();
        soundManager.Play(gunFireSound);

        loadedBullets--;
        UpdateAmmoText();

        fireTimer = 0.0f;
    }