How to get the highest score player?

Hi I am working on a game based on PUNMMORPGDemo, want to end the game when someone first get the highest score. Should I use PhotonNetwork.player.getscore or something like sendmessage ? > _ <
And by the way, when game is over I want all player move to oneplace like overwatch, how can I change their camera to one fixed camera?

Comments

  • Hi @XiannvYou,

    yes, using the integrated score functionality is the way to go here. In this case there are multiple options to achieve what you want. The best might be to let the player - who got the target score - send a RPC in order to inform the others about his score. An extension therefore would be, that this player sends the RPC only to the MasterClient. The MasterClient can now check the score (see if it is correct) and send another RPC or call RaiseEvent to end the game.

    When you want to move the camera to a certain point (fixed position and orientation) you can do this in the same call you use to inform all clients about the end of the game. You don't really need to switch to another camera object, you can simply use the main camera in my opinion.
  • Thx! @Christian_Simon Let this player sends RPC to end the game is convenient, but I cant synchronize the gamestate by use this player sends the RPC to all targets.This script is on the playerobject. Only in RPC the camera.setactive can work with all players. I cant understand how the enum works.....叹气...
    • void Update () {
      if (m_PhotonView.isMine == true)
      {
      Updatestate();
      Endgame();
      }


      }
      void Updatestate()
      {
      if (PhotonNetwork.player.GetScore() == 2)
      {
      //Camera.SetActive(false);
      //EndCamera.SetActive(true);
      //Debug.Log("33");
      photonView.RPC("Finished", PhotonTargets.All);
      }


      }
      void Endgame()
      {
      if (state == MoState.FINISHED)
      {
      Debug.Log("33");
      Camera.SetActive(false);
      EndCamera.SetActive(true);
      }
      }
      [PunRPC]
      public void Finished()
      {
      state = MoState.FINISHED;
      //Camera.SetActive(false);
      //EndCamera.SetActive(true);
      //EndCamera.SetActive(true);
      }
  • Each entry of the enum can be bound to a certain int value, e.g. GameState.WaitingForOtherPlayers = 1, GameState.Ready = 2, GameState.Live = 3 etc. So in order to synchronize the game state you can again use RPCs with parameters. You can read about this on the related documentation page, which also provides a simple example about the usage of parameters. Another option here is to use the Custom Room Properties which can be also used for storing and updating the current game state.

    You can go the same way when it comes to the end of the game and you want to have another camera perspective. Let's assume that each client's camera should show the winner at the end of the match. The victorious player send a RPC with the target position and rotation of the camera (target position is a few units in front of the victorious player, rotation can be calculated by using LookAt(...) function). When receiving this RPC call other clients can update their camera by using Camera.main.transform.position and Camera.main.transform.rotation.