I am making a multiplayer game and I am a bit confused on how exactly the RPC function works.
For instance if I call an RPC that changes the gameobject name to “test” in RPCMode.All and each player has the script, will it change only for his model in every client or will it change everyone’s name to “test”.
What if I do the same thing but I call it from the server? For example:
I did it by simply changing the name on the server end, then sending the RPC to other players to change the instance name on their ends, like this:
[RPC]
void SendName (name : String)
{
yourNameVariable = name;
}
void Update ()
{
networkView.RPC("nameChange", RPCMode.All); //you can also use others here, if there are issues with server doing it wrong.
}
There you go. just some help i can give about RPCs. also hope I understood you correctly.
That there was just an example. you can use an RPC call anywhere you want. for something like a player being defeated, you would use an “if” statement or switch to decide when to tell the opponents a player has died. Kinda like this: (again, typing out of my head)
void Update () {
if (player.defeated) {
<do something>
networkView.RPC(<do something>, RPCMode.All, <parameters for do something>);
}
}
In your case, just have a Boolean variable in place for every time you change your name. that way, by clicking a button, the bool will come on, the RPC will be sent, then the bool could be set top false to prevent sending it again. Here’s another example: (if i got the syntax wrong, it’s because i am not used to C#!)
the typer variable could then be tied to a text field in OnGUI, to change the name easily. you can also tie a button to the bool variable in the same way.
Good luck!
-FuzzyQuills
EDIT: just changed the code to state the OnGUI function