- Home /
Question by
Domo23000 · May 04, 2014 at 07:29 PM ·
multiplayernetworkrpcusername
Network RPC
I made a script that changes the username, but I need to make it an RPC for all other players to see. Here's what I have so far.
var userName : String = "Guest000";
var maxChar : int = 10;
var nameTag : TextMesh;
private var isDone : boolean = false;
function Update()
{
nameTag.text = userName;
}
function OnGUI()
{
if (networkView.isMine)
{
if(isDone == false)
{
userName = GUI.TextField(Rect(0, 0, 100, 25), userName, maxChar);
if(GUI.Button(Rect(0, 25, 100, 25), "Done"))
{
isDone = true;
}
}
}
}
Comment
Answer by Kiloblargh · May 04, 2014 at 09:36 PM
You don't make a script an RPC, you make a function an RPC. And it can't be the OnGUI function.
No need to set nameTag.text every frame in Update ()
, only do that a single time when it changes.
if(GUI.Button(Rect(0, 25, 100, 25), "Done"))
{
isDone = true;
networkView.RPC ("GetName", RPCMode.Others, userName);
}
...
}
@RPC
function GetName (name : String, info : NetworkMessageInfo) {
//do something with info.sender here...
}
Your answer
Follow this Question
Related Questions
Does the position change need state synchronization? 2 Answers
get return on networkView.RPC 1 Answer
Error in runtime:"View ID AllocatedID: 6316 not found during lookup. Strange behaviour may occur" 1 Answer
How to use an RPC to send an animation over the network? 2 Answers
Multiplayer issue - players view others as themselves with same material 1 Answer