I have read the multiplayer tutorials.but I just could understand,and I read the manual and the Refferece
but im getting nothing out of it, so can some one explain me the idea of them?
I mean,I want to call Health Drop on player when he gets hitten by Raycast,
How can I do that? where do I need to invoke it? where do I need to write it,
I tried everything ( exept the right one Apparently ).
A RPC is a command, only it gets executed on the remote players.
Player A fires a raycast to player B.
Player A has to execute a command on player B to have his health decreased.
So Player A sends an RPC command :
networkView.RPC (“REMOTECOMMANDNAME”, RPCMode or ‘PlayerBnetworkView’ here, options);
Player B will execute command :
yep and i forgot to mention that it’s unidirectional, if you want the sender to get a reply, you will need to perform the same routine in the opposite direction.
You should get this first CruelStudios,as you know when you bound a script to a gameobject ,all same game objects with same scripts bounded on,will have that rpc function you wrote.What i mean is:
suppose that you have a script and named as CharacterOperations,and you have a function named DecreaseHealth with an integer parameter named damage.
suppose that you calculate a damage forexample in Update function and you pass that damage as a parameter to DecreaseHealth function and calculate new health for a unit.This works fine in single mod.In this architecture if you want to make your game multiplayer, you can write a RPC to send a data from one player to another player in network.Example
@RPC
function DecreaseHealthFromRemotePlayer(damage:int)
{
DecreaseHealth(damage);
}
function DecreaseHealth(damage:int)
{
currentHealth=currentHealth-damage;
}
What i have done here is,i made my single mode function DecreaseHealth able to work in network with a RPC DecreaseHealthFromRemotePlayer
What you should consider?
1-you can call RPC from same script bounded to an object.I mean the RPC function itself and the place you call rpc should be in same script.On the other hand you can call a RPC from different script but from a tricky way.
2-there are limitations for rpc parameters so first of all you should decide what to send
3-ask yourself that ,is using rpc a better solution then using serializing in this situation?