Search Unity

  1. We have added dedicated sub-forums for UNet, the experimental MLAPI and Unity Transport Package. Please use the new forums to discuss related topics.
    Dismiss Notice
  2. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Sending strings from client to client with Photon

Discussion in 'Multiplayer' started by P14SU, Jul 15, 2021.

  1. P14SU

    P14SU

    Joined:
    May 27, 2021
    Posts:
    3
    Hello all,

    I am building a chess game with Unity and trying to make it multi-player. My problem is that I do not want to synchronize object placements/movement as one player will be white and the other player black and their screens should be mirrored. I have created a dictionary with all the coordinates for all of the squares, so all I need to do is send the string "a2,a3" from one client to another and the piece on a2 will move to a3.

    However, I don't know how to do this and no tutorial seems to help (all tutorials seem to be about syncing the placements of objects which I don't want as their positions on each screen will be different). Is there not a way whenever I move a piece on one board with coordinates those exact same coordinates can be transmitted as a string to the other player (where their client can then parse that string to make a paralleled movement)?

    Thanks in advance!
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,642
    You should assign a single number as id for each field. Then you can send moves via RaiseEvent:
    Code (CSharp):
    1. PhotonNetwork.RaiseEvent(evCodeForMove, squaresFromTo, RaiseEventOptions.Default, SendOptions.SendReliable);
    The other player will receive an event. Implement OnEvent, check the code and content (squaresFromTo might be an byte[], eg.) and act accordingly.
     
  3. P14SU

    P14SU

    Joined:
    May 27, 2021
    Posts:
    3
    So let's say my string is "a2,a3" to move the piece on a2 to a3. For this I will have:

    Code (CSharp):
    1. string coords = "a2, a3"
    2.  
    3. //on moving the piece
    4.  
    5. PhotonNetwork.RaiseEvent(coords, RaiseEventOptions.Default, SendOptions.Reliable);
    6.  
    7. //on the other client
    8.  
    9. OnEvent()
    10. {
    11. coords = coords
    12. //do stuff
    13.  
    14. }
    Something like that? It doesn't look right. I don't understand why there's four parameters in RaiseEvent.
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,559
    You need to send an event code with RaiseEvent, so that you can identify the event on the receiver, you are missing that in your example.

    That aside, I don't see why you can't have a single board layout with all the pieces synchronized and just have each player's camera at opposite sides of the board.
     
unityunity