- Home /
RPC function to update clients varialbe
Ok so I have this network script that works really well except for when I want to spawn a player at a different location. Im basing location on the number of current players connect. Right now the variable is updating right on the server so that good. But when a client joins the game, the player count for him is 0. I want to set that to the current number of players connected from the server variable. I was messing around with RPC functions but with no luck.
So this is what I have so far any help would be very appreciated.
//spwan the master jumper
function OnServerInitialized()
{
Debug.Log("Server initilized");
playerCount++;
spawnPlayer(sp1);
}
function OnPlayerConnected(networkPlayer:NetworkPlayer):void
{
Debug.Log (networkPlayer.guid + " connected");
playerCount++;
//spawnPlayer(sp2);
//spawning player here does not work! Just a black screen no cam perhaps
}
function OnConnectedToServer()
{
//loop though every object in the game
for(var go : GameObject in FindObjectsOfType(GameObject))
{
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
Debug.Log("Connected to server");
Debug.Log("Player Count: " + playerCount);
if(playerCount ==0)
{
sp = sp1;
}
if(playerCount ==1)
{
sp = sp2;
}
if(playerCount ==2)
{
sp = sp3;
}
if(playerCount ==4)
{
sp = sp4;
}
spawnPlayer(sp);
}
//spawn player prefab
function spawnPlayer(SP : Transform)
{
Network.Instantiate(playerPrefab, SP.position, Quaternion.identity, 0);
//Network.Instantiate(playerPrefab, spawnPoints[playerCount].position, Quaternion.identity, 0);
}
@RPC
function SendPlayerCount()
{
//send playercount to client from server
}
@RPC
function RecivePlayerCount()
{
//get playercount from server
//playerCount = playerCount;
}
If every player knows that every other player has spawned, why not just count the number of spawned players, rather than using up your bandwidth with useless information?
Well i tried something like that but the player count just is zero even if there are 3 or 4 player connected to the server
Im just working on figuring out RPC what one was intended to do is send the number of players from the server the other is to receive the number of players on the client side
Your answer
Follow this Question
Related Questions
Network - Killing Player, Then Respawn - Issue with RPC 1 Answer
Network initializing player 1 Answer
Mutliplayer SetActive(true) 0 Answers
Network.Instantiate spawns multiple objects 2 Answers
RPC a lot of lags (Photon) 0 Answers