Example #1
0
        List <NetworkPrint> players = new List <NetworkPrint>(); // Creating List of players in the room

        void OnPhotonInstantiate(PhotonMessageInfo info)
        {
            singleton = this;
            DontDestroyOnLoad(this.gameObject);

            InstantiateNetworkPrint();
        }
        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 EndMatch(MultiplayerManager mm, bool isWinner)
        {
            if (PhotonNetwork.InRoom)
            {
                PhotonNetwork.LeaveRoom();
            }

            this.isWinner.value = isWinner;
            mm.ClearReferences();
            LoadMainMenuFromGame();
        }
        void IPunInstantiateMagicCallback.OnPhotonInstantiate(PhotonMessageInfo info)
        {
            Debug.Log("(1) Multiplayer Manager: OnPhotonInstantiate called");
            singleton = this;
            DontDestroyOnLoad(this.gameObject);

            mRef = new MultiplayerReferences();
            DontDestroyOnLoad(mRef.referencesParent.gameObject);
            InstantiateNetworkPrint();
            currentTime = startingTime;

            isMaster = PhotonNetwork.IsMasterClient;
        }
        void IPunInstantiateMagicCallback.OnPhotonInstantiate(PhotonMessageInfo info)
        {
            MultiplayerManager mm = MultiplayerManager.singleton;

            photonId = photonView.OwnerActorNr;
            isLocal  = photonView.IsMine;

            //This data is then passed to Instantiate Controller-ish
            object[] data = photonView.InstantiationData;
            weapon  = (string)data[0];
            modelId = (string)data[1];

            mm.AddNewPlayer(this);
        }
Example #6
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);
            }
        }
Example #7
0
        public void OnPhotonInstantiate(PhotonMessageInfo info)
        {
            states = GetComponent <StateManager>();
            states.InitReferences();
            mTransform = this.transform;
            object[] data = photonView.InstantiationData;

            states.photonId = (int)data[0];
            string modelId = (string)data[2];

            states.LoadCharacterModel(modelId);

            MultiplayerManager m = MultiplayerManager.singleton;

            this.transform.parent = m.GetMRef().referencesParent;

            PlayerHolder playerHolder = m.GetMRef().GetPlayer(states.photonId);

            playerHolder.states = states;

            string weaponId = (string)data[1];

            Debug.Log("Weapon ID: " + weaponId);
            states.inventory.weaponID = weaponId;

            if (photonView.IsMine)
            {
                states.isLocal = true;
                states.SetCurrentState(local);
                initLocalPlayer.Execute(states);
            }
            else
            {
                states.isLocal = false;
                states.SetCurrentState(client);
                initClientPlayer.Execute(states);
                states.multiplayerListener = this;
            }
        }