PUN2 Ability Synchronisation

Options
Hello I am making a game with unity were there are 2 players with diferent abilities.
The abilities are scripts placed on buttons. When someone presses an ability button the ability executes.
For example the first player has a button with an ability script that moves a cube up and the other player has a button with an ability script that destroys the same cube.
How can eatch player synchronise his ability action with the other?
I thought of using RPCs but because eatch player has his unique script and button, it can't work.
What sould I do?

Comments

  • Tobias
    Options
    Check out RaiseEvent. It's independent from networked objects / PhotonViews.
    https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent
  • BillyTheKid
    Options
    I checked it out and I have a question. The code that triggers the event will be on the ability scripts. Where should I put the code that recieves the event and does the action?
  • seeevil
    Options
    first step
    private void OnEnable()
        {
            PhotonNetwork.NetworkingClient.EventReceived += NetworkingClientOnEventReceived;
        }
    
    private void OnDisable()
        {
            PhotonNetwork.NetworkingClient.EventReceived -= NetworkingClientOnEventReceived;
        }
    

    second step
    private void NetworkingClientOnEventReceived(EventData obj)
        {
            if (obj.Code == your_code)
            {
                //DO SOMETHING
                
            }
        }
    

    but do not forget to send before you receive an answer
    @BillyTheKid
  • BillyTheKid
    Options
    Where should I put the code of the second step that receives the event. I can't put it in the ability script because each player has his unique ability script. Should I make a new script that is common for both players and it's running the code of the second step?