title: Photon Unity Turn based Multiplayer game
body: <p>I am trying to create a simple 2D Turn based multiplayer game using Photon Unity Networking. </p>
  
  <p>It is just a simple turn based game where a <code>player 1</code> (host) presses his button and it adds his score and changes its turn to <code>player 2</code> (client) who presses his button to add score and change turn to <code>player 1</code>. It continues to infinite. </p>
  
  <p>I was able to connect two players in the game using the basic <code>Photon</code> documentation. Now I need to add the networking logic of taking turns and changing them. </p>
  
  <p>I searched the internet but I can't understand the <code>RPC</code> and <code>SerializeView</code> of Photon. I am really confused with that. Please Help me. Thank you in future. Here is my <code>GameManager</code> Script</p>
  
  <pre class="lang-c# prettyprint-override"><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.SceneManagement;
  using UnityEngine.UI;
  
  public class GameManager : Photon.PunBehaviour
  {    
      public Text roomName;
      public Text player1Name,player2Name;
      public List&lt;string&gt; playersConnected = new List&lt;string&gt;();
      int scoreP1 = 0, scoreP2 = 0;
      public Text scoreTextP1, scoreTextP2;
      public Button p1Btn, p2Btn;
      int playerTurn = 1;
  
      void Start()
      {
          roomName.text = SceneManager.GetActiveScene().name;
          p2Btn.gameObject.SetActive(false);
          p1Btn.gameObject.SetActive(true);
      }    
  
      public void AddScoreP1()
      {
          scoreP1++;
          scoreTextP1.text = scoreP1.ToString();
          ChangePlayerTurn();
      }
  
  
      public void AddScoreP2()
      {
          scoreP2++;
          scoreTextP2.text = scoreP2.ToString();
          ChangePlayerTurn();
      }
  
      void ChangePlayerTurn()
      {
          if (playerTurn == 1)
          {
              playerTurn = 2;
              p2Btn.gameObject.SetActive(true);
              p1Btn.gameObject.SetActive(false);
          }
          else
          {
              playerTurn = 1;
              p1Btn.gameObject.SetActive(true);
              p2Btn.gameObject.SetActive(false);
          }
          print("Player Turn: P" + playerTurn);
      }
  
      void LoadArena()
      {
          if (!PhotonNetwork.isMasterClient)
          {
              Debug.LogError("PhotonNetwork : Trying to Load a level but we are not the master Client");
          }
          Debug.Log("PhotonNetwork : Loading Level : " + PhotonNetwork.room.PlayerCount);
          PhotonNetwork.LoadLevel("Room for " + PhotonNetwork.room.PlayerCount);
      }
  
      public override void OnLeftRoom()
      {
          SceneManager.LoadScene(0);
      }      
  
      public void LeaveRoom()
      {
          PhotonNetwork.LeaveRoom();
      }
  
      public override void OnPhotonPlayerConnected(PhotonPlayer other)
      {
          Debug.Log("OnPhotonPlayerConnected() " + other.NickName); // not seen if you're the player connecting
          foreach (PhotonPlayer _player in PhotonNetwork.playerList)
          {
              playersConnected.Add(other.NickName);
          }
  
          if (PhotonNetwork.isMasterClient)
          {
              Debug.Log("OnPhotonPlayerConnected isMasterClient " + PhotonNetwork.isMasterClient); // called before OnPhotonPlayerDisconnected
  
              LoadArena();
          }
      }
  
      public override void OnPhotonPlayerDisconnected(PhotonPlayer other)
      {
          Debug.Log("OnPhotonPlayerDisconnected() " + other.NickName); // seen when other disconnects
          foreach (PhotonPlayer _player in PhotonNetwork.playerList)
          {
              playersConnected.Remove(other.NickName);
          }
  
          if (PhotonNetwork.isMasterClient)
          {
              Debug.Log("OnPhotonPlayerDisonnected isMasterClient " + PhotonNetwork.isMasterClient); // called before OnPhotonPlayerDisconnected
              LoadArena();
          }
      }
  }
  </code></pre>