I’m running a web player/server game. Let’s look at the code first and I’ll show you the problem I’m running into:
Server code:
function Start () {
Network.InitializeServer(32, 25000);
}
Client code:
Script attached to the main camera or a dummy object:
// "playerPrefab" is assigned to a prefab which is an empty object.
var playerPrefab : Transform;
function Start () {
Network.Connect("127.0.0.1", 25000);
}
function OnConnectedToServer(){
Network.Instantiate(playerPrefab, Vector3(0,0,0), Quaternion.identity, 0);
}
Script attached to “playerPrefab”:
var playername : String = "";
function OnNetworkInstantiate(info : NetworkMessageInfo)
{
if( networkView.isMine )
{
var name = "any";
networkView.RPC( "SetPlayerName", RPCMode.AllBuffered, name );
}
}
@RPC
function SetPlayerName( name : String )
{
print("SetPlayerName:" + name);
gameObject.name = name;
}
Both client and server runs in windows. Server runs as a standalone app. One client runs in Unity, and another one runs in browser. When I run client from Unity, I see “SetPlayerName:any” in the console, then I run another client in browser, I’m expecting to see another line of “SetPlayerName:any” in the console, but what I get is “SetPlayerName:playerPrefab(clone)”. It means “SetPlayerName” is not called. But it’s a buffered RPC which SHOULD be called on every client, isn’t it?
Did I miss something in order for this to work?