Ejemplo n.º 1
0
        protected virtual void RpcRespawn()
        {
            //toggle visibility for player gameobject (on/off)
            gameObject.SetActive(!gameObject.activeInHierarchy);
            bool isActive = gameObject.activeInHierarchy;

            //the player has been killed
            if (!isActive)
            {
                //detect whether the current user was responsible for the kill
                //yes, that's my kill: take thumbnail via EveryPlay
                if (killedBy == GameManager.GetInstance().localPlayer.gameObject)
                {
                    UnityEveryplayManager.TakeThumbnail();
                }

                if (explosionFX)
                {
                    //spawn death particles locally using pooling and colorize them in the player's team color
                    GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                    ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                    if (pColor)
                    {
                        pColor.SetColor(GameManager.GetInstance().teams[GetView().GetTeam()].material.color);
                    }
                }

                //play sound clip on player death
                if (explosionClip)
                {
                    AudioManager.Play3D(explosionClip, transform.position);
                }
            }

            //further changes only affect the local client
            if (!photonView.isMine)
            {
                return;
            }

            //local player got respawned so reset states
            if (isActive == true)
            {
                ResetPosition();
            }
            else
            {
                //local player was killed, set camera to follow the killer
                camFollow.target = killedBy.transform;
                //hide input controls and other HUD elements
                camFollow.HideMask(true);
                //display respawn window (only for local player)
                GameManager.GetInstance().DisplayDeath();
            }
        }
Ejemplo n.º 2
0
        public void RpcDie(short senderId)
        {
            gameObject.SetActive(false);
            killedBy = senderId > 0 ? ClientScene.FindLocalObject(new NetworkInstanceId((uint)senderId)) : null;
            bIsAlive = false;
            // TODO: ScoreBegin
            if (explosionFX != null)
            {
                //spawn death particles locally using pooling and colorize them in the player's team color
                GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                if (pColor)
                {
                    pColor.SetColor(GameManager.GetInstance().teams[teamIndex].material.color);
                }
            }

            //play sound clip on player death
            if (explosionClip != null)
            {
                AudioManager.Play3D(explosionClip, transform.position);
            }

            if (isServer)
            {
                agent.Warp(GameManager.GetInstance().GetSpawnPosition(teamIndex));
            }

            if (controller != null)
            {
                controller.Stop();
            }

            if (isLocalPlayer)
            {
                if (killedBy != null)
                {
                    camFollow.target = killedBy.transform;
                }
                camFollow.HideMask(true);
                GameManager.GetInstance().DisplayDeath();
            }
        }
Ejemplo n.º 3
0
        protected virtual void RpcRespawn(short senderId)
        {
            //toggle visibility for player gameobject (on/off)
            gameObject.SetActive(!gameObject.activeInHierarchy);
            bool isActive = gameObject.activeInHierarchy;

            killedBy = null;

            //the player has been killed
            if (!isActive)
            {
                //find original sender game object (killedBy)
                PhotonView senderView = senderId > 0 ? PhotonView.Find(senderId) : null;
                if (senderView != null && senderView.gameObject != null)
                {
                    killedBy = senderView.gameObject;
                }

                //detect whether the current user was responsible for the kill, but not for suicide
                //yes, that's my kill: increase local kill counter
                if (this != GameManager.GetInstance().localPlayer&& killedBy == GameManager.GetInstance().localPlayer.gameObject)
                {
                    GameManager.GetInstance().ui.killCounter[0].text = (int.Parse(GameManager.GetInstance().ui.killCounter[0].text) + 1).ToString();
                    GameManager.GetInstance().ui.killCounter[0].GetComponent <Animator>().Play("Animation");
                }

                if (explosionFX)
                {
                    //spawn death particles locally using pooling and colorize them in the player's team color
                    GameObject    particle = PoolManager.Spawn(explosionFX, transform.position, transform.rotation);
                    ParticleColor pColor   = particle.GetComponent <ParticleColor>();
                    if (pColor)
                    {
                        pColor.SetColor(GameManager.GetInstance().teams[GetView().GetTeam()].material.color);
                    }
                }

                //play sound clip on player death
                if (explosionClip)
                {
                    AudioManager.Play3D(explosionClip, transform.position);
                }
            }

            if (PhotonNetwork.IsMasterClient)
            {
                //send player back to the team area, this will get overwritten by the exact position from the client itself later on
                //we just do this to avoid players "popping up" from the position they died and then teleporting to the team area instantly
                //this is manipulating the internal PhotonTransformView cache to update the networkPosition variable
                GetComponent <PhotonTransformView>().OnPhotonSerializeView(new PhotonStream(false, new object[] { GameManager.GetInstance().GetSpawnPosition(GetView().GetTeam()),
                                                                                                                  Vector3.zero, Quaternion.identity }), new PhotonMessageInfo());
            }

            //further changes only affect the local client
            if (!photonView.IsMine)
            {
                return;
            }

            //local player got respawned so reset states
            if (isActive == true)
            {
                ResetPosition();
            }
            else
            {
                //local player was killed, set camera to follow the killer
                if (killedBy != null)
                {
                    camFollow.target = killedBy.transform;
                }
                //hide input controls and other HUD elements
                camFollow.HideMask(true);
                //display respawn window (only for local player)
                GameManager.GetInstance().DisplayDeath();
            }
        }