Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

RPC Calls Confusion

Discussion in 'Multiplayer' started by JD_FVTC, Oct 20, 2020.

  1. JD_FVTC

    JD_FVTC

    Joined:
    Oct 20, 2017
    Posts:
    54
    When the second player enters the game I want to tell MasterClient to start the Game audio.
    when Audio ends I want to show the question and sets of answers for each player to select.
    I get 2 sets of answers on the Master player but not anything the other 2nd player.

    Am I calling my RPC's Incorrectly?

    Code (CSharp):
    1.  
    2. PhotonView PV;
    3.     void Start()
    4.     {
    5.    
    6.         PV = gameObject.GetComponent<PhotonView>();
    7.     }
    8.     public override void OnJoinedRoom()
    9.     {
    10.         if (PhotonNetwork.CurrentRoom.PlayerCount > 1)
    11.         {
    12.           [COLOR=#ff4d4d]  PV.RPC("PlayStartGameAudio", RpcTarget.MasterClient);[/COLOR]
    13.         }
    14.     }
    15.     [PunRPC]
    16.     public IEnumerator PlayStartGameAudio()
    17.     {
    18.         StartGameAudioClip.Play();
    19.         yield return new WaitForSeconds(2.0f);
    20.       [COLOR=#ff4d4d]  this.photonView.RPC("StartTheGame", RpcTarget.AllViaServer);[/COLOR]
    21.     }
    22.     [PunRPC]
    23.     public void StartTheGame()
    24.     {
    25.         if (PV.IsMine)
    26.         {
    27.             questionNumber = 0;
    28.             scoreBoardManagr_player1.ResetScore();
    29.             scoreBoardManagr_player2.ResetScore();
    30.             theCurrentQuestion = gameObject.GetComponent<GetTheQuestions>().GetTheQuestion(questionNumber);
    31.             int i = 0;
    32.             foreach (TextMeshPro questionboard in questionboards)
    33.             {
    34.                 questionboards[i].SetText(theCurrentQuestion.Text);
    35.                 i++;
    36.             }
    37.           [COLOR=#ff4d4d]  this.photonView.RPC("LaunchAnswers", RpcTarget.AllViaServer);[/COLOR]
    38.         }
    39.     }
    40.     [PunRPC]
    41.     public IEnumerator LaunchAnswers()
    42.     {
    43.         if (PV.IsMine)
    44.         {
    45.    
    46.             int answerCount = 0;
    47.             var angle = .01f;
    48.      
    49.             foreach (GetTheQuestions.Answer answer in theCurrentQuestion.Answers)
    50.             {
    51.                 answerGo = PhotonNetwork.Instantiate(answerfab.name, launcher_Player1[answerCount].transform.position, Quaternion.identity);
    52.                 answerGo.GetComponent<TextMeshPro>().text = theCurrentQuestion.Answers[answerCount].Text;
    53.                 answers.Add(answerGo);
    54.                
    55.                 answerCount++;
    56.                 answerGo.GetComponent<RotateAroundAnObject>().angle += angle;
    57.                 angle += .1f;
    58.                 yield return new WaitForSeconds(0.1f);
    59.             }
    60.         }
    61.         else
    62.         {
    63.          
    64.             int answerCount = 0;
    65.             var angle = .01f;
    66.      
    67.             foreach (GetTheQuestions.Answer answer in theCurrentQuestion.Answers)
    68.             {
    69.                 answerGo = PhotonNetwork.Instantiate(answerfab.name, launcher_Player2[answerCount].transform.position, Quaternion.identity);
    70.                 answerGo.GetComponent<TextMeshPro>().text = theCurrentQuestion.Answers[answerCount].Text;
    71.                 answers.Add(answerGo);
    72.              
    73.                 answerCount++;
    74.                 answerGo.GetComponent<RotateAroundAnObject>().angle += angle;
    75.                 angle += .1f;
    76.                 yield return new WaitForSeconds(0.1f);
    77.             }
    78.         }
    79.     }
    80.  
    81.  
    82.