Hi,
I’ve noticed a bit of an inconsistency when trying to set up my game. When I start a new game, I want the server to set the necessary parameters and then send a message to clients (including the server itself) to show a screen. However at the moment I’m having to put a delay in, in order to make it work consistently. All functions below are in the same class which derives from a NetworkBehaviour.
public override void OnStartServer ()
{
if(LobbyManager.singleton.numPlayers == PlayerManager.instance.GetNumberOfPlayers())
{
StartServer();
}
base.OnStartServer ();
}
Server functions below:
[Server]
public void StartServer()
{
StartCoroutine (ServerNewGame ());
}
[Server]
IEnumerator ServerNewGame()
{
yield return new WaitForSeconds (1f);
RelationshipInitializer.Instance.Initialize();
ChangeCampaign();
}
[Server]
public void ChangeCampaign()
{
Campaign newCampaign = new Campaign();
RpcStartBudgetAllocation ();
}
ClientRPC function.
[ClientRpc]
public void RpcStartBudgetAllocation()
{
PickBudgetScreen.Instance.ShowScreen ();
}
I’m noticing however that without the delay in my ServerNewGame function, the RpcStartBudgetAllocation function is not called at all. Not on the client on the server or any other clients.
Is there a particular reason why or a better way I should do this?