Exemplo n.º 1
0
        public void ClientShoot(StateManager states, Vector3 dir, Vector3 origin)
        {
            Ray ray = new Ray(origin, dir);

            Debug.DrawLine(origin, dir);
            RaycastHit[] hits;

            hits = Physics.RaycastAll(origin, dir, 100);
            if (hits == null)
            {
                return;
            }
            if (hits.Length == 0)
            {
                return;
            }

            RaycastHit closestHit;

            closestHit = GetClosestHit(origin, hits, states.photonId);

            IHittable isHittable = closestHit.transform.GetComponentInParent <IHittable>();

            if (isHittable == null)
            {
                GameObject hitParticle = GameManagers.GetObjectPool().RequestObject("Bullet_Impact_FX");
                Quaternion rot         = Quaternion.LookRotation(-dir);
                hitParticle.transform.position = closestHit.point;
                hitParticle.transform.rotation = rot;
            }
            else
            {
                isHittable.OnHit(states, states.inventory.currentWeapon, dir, closestHit.point);
            }
        }
        public void OnHit(StateManager shooter, Weapon w, Vector3 dir, Vector3 pos)
        {
            if (shooter == this)
            {
                return;
            }

            Debug.Log("Player has been hit by: " + shooter.photonId);
            GameObject hitParticle = GameManagers.GetObjectPool().RequestObject("BloodSplat_FX");
            Quaternion rot         = Quaternion.LookRotation(-dir);

            hitParticle.transform.position = pos;
            hitParticle.transform.rotation = rot;

            if (Photon.Pun.PhotonNetwork.IsMasterClient)
            {
                if (!isDead)
                {
                    stats.health -= w.ammoType.damageValue;
                    MultiplayerManager mm = MultiplayerManager.singleton;
                    mm.BroadcastPlayerHealth(photonId, stats.health, shooter.photonId);

                    if (stats.health <= 0)
                    {
                        Debug.Log("Player: " + this.photonId + " has been killed by: " + shooter.photonId);
                        isDead = true;
                    }
                }
            }
        }
        public void OnHit(StateManager shooter, Weapon w, Vector3 dir, Vector3 pos)
        {
            GameObject hitParticle = GameManagers.GetObjectPool().RequestObject(targetParticle);
            Quaternion rot         = Quaternion.LookRotation(-dir);

            hitParticle.transform.position = pos;
            hitParticle.transform.rotation = rot;
        }
Exemplo n.º 4
0
        public override void Execute(StateManager states, Weapon w)
        {
            Vector3 origin = w.runtime.modelInstance.transform.position;
            Vector3 dir    = states.movementValues.aimPosition - origin;


            Ray ray = new Ray(origin, dir);

            Debug.DrawLine(origin, dir);
            RaycastHit[] hits;

            hits = Physics.RaycastAll(origin, dir, 100);
            if (hits == null)
            {
                return;
            }
            if (hits.Length == 0)
            {
                return;
            }

            RaycastHit closestHit;

            closestHit = GetClosestHit(origin, hits, states.photonId);

            IHittable isHittable = closestHit.transform.GetComponentInParent <IHittable>();

            if (isHittable == null)
            {
                Debug.Log("isHittable was null");
                GameObject hitParticle = GameManagers.GetObjectPool().RequestObject("Bullet_Impact_FX");
                Quaternion rot         = Quaternion.LookRotation(-dir);
                hitParticle.transform.position = closestHit.point;
                hitParticle.transform.rotation = rot;
            }
            else
            {
                Debug.Log("The object hit is: " + closestHit);
                isHittable.OnHit(states, w, dir, closestHit.point);
            }



            MultiplayerManager mm = MultiplayerManager.singleton;

            if (mm != null)
            {
                mm.BroadcastShootWeapon(states, dir, origin);
            }
        }