Search Unity

Third Party Send and Receive Custom Initiation Data Photon

Discussion in 'Multiplayer' started by plusplusgames, Nov 12, 2022.

  1. plusplusgames

    plusplusgames

    Joined:
    Jul 26, 2021
    Posts:
    69
    I'm trying to send and receive a string and int on some Custom Initiation Data, but I can't seem to either send or receive either one. I have been trying for hours now but no luck, please help:



    Send Script:

    Code (CSharp):
    1.  
    2. public string snakeName;
    3.  
    4.  
    5. public float minZ;
    6.  
    7.  
    8. void Start()
    9.  
    10.     {
    11.  
    12.  
    13.         snakeName = PlayerPrefs.GetString("urName");
    14.  
    15.  
    16.         object[] myCustomInitData = new object[]
    17.  
    18.         {
    19.  
    20.             minZ,
    21.  
    22.             snakeName
    23.  
    24.         };
    25.  
    26.  
    27.         PhotonNetwork.Instantiate(playerPrefab.name, randomPoiition, Quaternion.identity, 0, myCustomInitData);
    28.  
    29.     }


    Receive Script:

    Code (CSharp):
    1.  
    2.  
    3. private PhotonView view;
    4.  
    5.  
    6.     public int id;
    7.  
    8.  
    9.     public string snakeName;
    10.  
    11.  
    12.     public void OnPhotonInstantiate(PhotonMessageInfo info)
    13.  
    14.     {
    15.  
    16.         object[] instantiationData = info.photonView.InstantiationData;
    17.  
    18.         id = (int)instantiationData[0];
    19.  
    20.         snakeName = (string)instantiationData[1];
    21.  
    22.  
    23.  
    24.         this.gameObject.name = snakeName;
    25.  
    26.     }}