Search Unity

Instantiated GO with text set only shows on Player1?

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

  1. JD_FVTC

    JD_FVTC

    Joined:
    Oct 20, 2017
    Posts:
    54
    When I Instantiate a prefab and set its textmeshpro text on the master client the text doesn't show up on the other clients. Whats the proper way to sync the text over the network.

    The game objects get instantiated and movement is synced on both players but player 2 only has the default text not the text set by the master when instantiated.

    The master or first player text shows correctly.
    Any ideas what I'm doing wrong?

    Code (csharp):
    1.  
    2.  public void StartTheGame()
    3.     {
    4.         if (PhotonNetwork.IsMasterClient)
    5.         {
    6.         PV.RPC("LaunchAnswers", RpcTarget.MasterClient, answer1);
    7.         }
    8.     }
    9. [s][/s]
    10.    [PunRPC]
    11.     public void LaunchAnswers(string as1)
    12.     {
    13.         answer1 = as1;
    14.         var angle = .01f;
    15.         if (PV.IsMine)
    16.         {
    17.          
    18.             answerGo = PhotonNetwork.Instantiate(answerfab.name, launcher_Player1[0].transform.position, Quaternion.identity);
    19.             answerGo.GetComponent<TextMeshPro>().text = answer1.ToString() + "_Mine";
    20.             answerGo.GetComponent<RotateAroundAnObject>().angle += angle;
    21.             answerGop2 = PhotonNetwork.Instantiate(answerfab.name, launcher_Player2[0].transform.position, Quaternion.Inverse(Quaternion.identity));
    22.             answerGop2.GetComponent<TextMeshPro>().text = answer1.ToString() + "_Not Mine";
    23.             answerGop2.GetComponent<RotateAroundAnObject>().angle += angle;
    24.         }
    25.        
    26.     }
    27.  
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    You are using RpcTarget.MasterClient. Send this to All or AllViaServer.
     
    kopf likes this.