Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm new to Unity Networking as well as networking in general. I am looking to call an RPC on multiple machines, but for the RPC to do something different if the machine executing the function is not the machine that made the initial call. Consider the following C# code:

int dloc(int p, NetworkMessageInfo m) {
    if (!m.networkView.isMine) {
        Debug.Log ("I didn't call this!");
        p = (p-1) * -1;
    }
    return p;
}

[RPC]
void drawCard(int p, NetworkMessageInfo info) {
    p = dloc (p, info);
    player[p].drawCard ();
}

Say I call the drawCard() function on one machine with 0 as the integer parameter. I would think that on that machine, p would maintain its value of 0, and on the other machine p would be reassigned 1. However, it seems both machines have p equal whatever value the host assigns p to be. What is the problem here, and how could I work around it?

share|improve this question
    
Can you please post the code where you call drawCard? I don't understand why you would think p would be different on each machine. If you send a 0 out to each client, why would it increment automatically? –  Ben Jan 19 at 12:18
    
Check out the different RPC Modes. You can directly send to just the server so the other objects should not get in the way or wonder if it is there call. RPCModeDocumentation –  Justin Markwell Jan 19 at 16:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.