Exemple #1
0
    public IEnumerator Shooting()
    {
        disableInteraction = true;
        WeaponStatsScriptableObject stats = character.currentClass.weapons[currentWeapon];

        switch (stats.fireType)
        {
        case WeaponStatsScriptableObject.FireType.burst:
            for (int i = 0; i < stats.burstRounds; i++)
            {
                Shoot();
                yield return(new WaitForSeconds(stats.burstFireDelay));
            }
            break;

        default:
            Shoot();
            break;
        }

        yield return(new WaitForSeconds(stats.fireRate));

        if (Input.GetButton("Fire1") && stats.fireType == WeaponStatsScriptableObject.FireType.auto && weaponAmmo[currentWeapon] > 0)
        {
            StartCoroutine(Shooting());
        }
        else
        {
            disableInteraction = false;
        }
    }
Exemple #2
0
    public void Shoot()
    {
        WeaponStatsScriptableObject stats = character.currentClass.weapons[currentWeapon];

        source.PlayOneShot(stats.clip);
        int bulletAmount = stats.multipleShots ? stats.shotAmount : 1;

        switch (stats.projectileType)
        {
        case WeaponStatsScriptableObject.ProjectileType.rayCast:
            RaycastHit hit = new RaycastHit();
            for (int i = 0; i < bulletAmount; i++)
            {
                if (Physics.Raycast(Camera.main.transform.position, getSpreadDirection(Camera.main.transform.forward, stats.spread), out hit, stats.raycastFireLength))
                {
                    if (hit.transform.tag == enemyTag && !stats.explodingBullets)
                    {
                        GameObject currentObject = hit.transform.gameObject;
                        while (!currentObject.GetComponent <RemovableLimbs>())
                        {
                            currentObject = currentObject.transform.parent.gameObject;
                        }
                        currentObject.GetComponent <RemovableLimbs>().DoDamage(hit.collider, stats.damage, hit.point - Camera.main.transform.forward, stats.force, PhotonNetwork.playerName);
                    }
                    else if (stats.explodingBullets)
                    {
                        Collider[] enemyParts = Physics.OverlapSphere(hit.point, stats.explosionRadius, enemyMask);
                        GameObject.FindWithTag("Manager").GetPhotonView().RPC("CallScreenShake", PhotonTargets.All, stats.explosionScreenShakeTime, stats.explosionScreenShakeIntensity, hit.point);
                        foreach (Collider col in enemyParts)
                        {
                            GameObject currentObject = col.gameObject;
                            while (!currentObject.GetComponent <RemovableLimbs>())
                            {
                                currentObject = currentObject.transform.parent.gameObject;
                            }
                            Vector3 explosionPoint = hit.point + (Vector3.down / 3) - (Camera.main.transform.forward / 4);
                            currentObject.GetComponent <RemovableLimbs>().DoDamage(col, stats.explosionDamage, explosionPoint, stats.force, PhotonNetwork.playerName);
                        }
                        GameObject.FindWithTag("Manager").GetPhotonView().RPC("SpawnParticle", PhotonTargets.All, stats.explosionParticleIndex, hit.point, Quaternion.identity, null);
                    }
                }
            }
            break;

        case WeaponStatsScriptableObject.ProjectileType.projectile:
            source.PlayOneShot(stats.clip);
            for (int i = 0; i < bulletAmount; i++)
            {
                GameObject g = PhotonNetwork.Instantiate(stats.projectileName, info.firePoint.position, info.firePoint.rotation, 0);
                g.GetPhotonView().RPC("SetInformation", PhotonTargets.All, stats.explosionTimer, getSpreadDirection(Camera.main.transform.forward, stats.spread), stats.fireStrenght, stats.explosionDamage, stats.explosionRadius, stats.explosionParticleIndex, stats.force);
            }
            break;
        }
        weaponAmmo[currentWeapon]--;
        photonView.RPC("Recoil", PhotonTargets.All, stats.backwardsRecoil, stats.horizontalRotationRecoil);
    }