I’m trying to make it so that the first player to connect to a server will be assigned a particular controller and subsequent player will be assigned a different controller. I’ve set up a series of @RPC calls which should update variables which determine which controller the player spawns. However, players always spawn with the first controller. Here is my abridged code:
var isRTS : boolean=false;
var hasPlayer : boolean=false;
...
function OnServerInitialized(){
Debug.Log("Server initialized");
if(isRTS == false){
Debug.Log("No RTS Player.");
spawnRTSPlayer();
}
else
Debug.Log("RTS Player Present.");
spawnPlayer();
}
function OnConnectedToServer(){
if(isRTS == false){
Debug.Log("No RTS Player.");
spawnRTSPlayer();
}
else
Debug.Log("RTS Player Present.");
spawnPlayer();
}
...
function spawnPlayer(){
if(hasPlayer == false){
Debug.Log("Spawning Player");
GetComponentInChildren(Camera).enabled = false;
Network.Instantiate(playerPrefab, playerspawn.position, Quaternion.identity, 0);
networkView.RPC("HasPlayer", RPCMode.AllBuffered);
}
}
function spawnRTSPlayer(){
if(hasPlayer == false){
Debug.Log("Spawning RTS");
GetComponentInChildren(Camera).enabled = false;
Network.Instantiate(RTSPrefab, rtsspawn.position, Quaternion.Euler(50, 0, 0), 0);
networkView.RPC("RTSPlayerCount", RPCMode.AllBuffered);
networkView.RPC("HasPlayer", RPCMode.AllBuffered);
}
}
@RPC
function RTSPlayerCount(){
Debug.Log("UpdatingRTSCount");
isRTS = true;
}
@RPC
function HasPlayer(){
Debug.Log("UpdatingHasPlayer");
hasPlayer = true;
}
Can anyone see why this wouldn’t be working? Thanks.