Exemplo n.º 1
0
    protected virtual void FireRPC_ProjectileWeapon(Vector3 targetPoint, string serializedDamageDetails)
    {
        WeaponDamageDetails weaponDamageDetails = JsonUtility.FromJson <WeaponDamageDetails>(serializedDamageDetails);

        //   parentRigidbody = transform.root.GetComponent<Rigidbody>();
        // debug function to fire weapon
        weaponAnimator.SetTrigger(primaryFireAnimatorTriggerName);
        //  Debug.Log("ProjectileWeapon class object has fired");

        // if we are the owner of the photonview, then fire the real projectile


        /*
         * PooledObject pooledProjectile =
         *  Pool.Instance.Spawn(projectilePrefab, barrelTransform.position, barrelTransform.rotation);
         *
         *
         * GameObject projectile = pooledProjectile.gameObject;
         */

        GameObject obj = projectilePrefab;
        //  StopProjectileCollisionsWithSelf(obj);
        GameObject projectile = Instantiate(obj, barrelEndMuzzleTransform.position, barrelEndMuzzleTransform.rotation);
        // StopProjectileCollisionsWithSelf(projectile);

        ProjectileScript projScript = projectile.GetComponent <ProjectileScript>();

        // set projscript stuff
        projScript.SetWeaponDamageDetails(weaponDamageDetails);
        projScript.ActivateProjectile(imapactParticle, missImpactParticle, projectileParticleEffectPrefab, impactParticleSound, impactParticleSoundMiss, imapactParticleVolume, missImpactParticleVolume);


        DoMuzzleFlashEffect();
        projectile.transform.LookAt(targetPoint);

        PlayAudioClipOneShot(weaponFireSound);
        projectile.GetComponent <PhysXRigidBody>().mass = projectileMass;
        // FIRE REAL PROJECTILE
        if (gunnerPhotonView.IsMine)
        {
            projScript.SetTrueProjectile(true);
            projectile.GetComponent <PhysXRigidBody>().AddForce(projectileSpeed * (projectile.transform.forward), ForceMode.VelocityChange);
            if (inheritVelocityFromVehicle)
            {
                projectile.GetComponent <PhysXRigidBody>().AddForce(parentRigidbody.velocity, ForceMode.VelocityChange);
            }
        }
        // add projectile settings
        // otherwise fire a lag compensated dummy projectile with no damage scripts enabled
        else
        {
            projScript.SetTrueProjectile(false);
            float ping = (PhotonNetwork.GetPing() * 1.0f) / 2;
            // update position by ping
            Vector3 newPos = projectile.transform.position + (projectile.transform.forward * (ping * 0.001f) * projectileSpeed);
            if (inheritVelocityFromVehicle)
            {
                newPos += parentRigidbody.velocity * ping * 0.001f;
            }

            projectile.transform.position = newPos;
            projectile.GetComponent <PhysXRigidBody>().AddForce(projectileSpeed * (projectile.transform.forward), ForceMode.VelocityChange);
        }

        Destroy(projectile, 4f);
        //pooledProjectile.Finish(4f);
    }