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?
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?
0
Comments
-
Check out RaiseEvent. It's independent from networked objects / PhotonViews.
https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent0 -
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?0
-
first step
private void OnEnable() { PhotonNetwork.NetworkingClient.EventReceived += NetworkingClientOnEventReceived; } private void OnDisable() { PhotonNetwork.NetworkingClient.EventReceived -= NetworkingClientOnEventReceived; }
second stepprivate void NetworkingClientOnEventReceived(EventData obj) { if (obj.Code == your_code) { //DO SOMETHING } }
but do not forget to send before you receive an answer
@BillyTheKid0 -
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?0