Skip to content

Instantly share code, notes, and snippets.

@glitchersgames
Last active July 8, 2016 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glitchersgames/afa6ae838b2f0cf2e55471dc0a21bf96 to your computer and use it in GitHub Desktop.
Save glitchersgames/afa6ae838b2f0cf2e55471dc0a21bf96 to your computer and use it in GitHub Desktop.
private List<Player> m_ClientPlayerObjects = new List<Player>();
private bool m_HasSentGameSceneReady = false;
private bool ShouldSendGameSceneReady
{
get
{
return
AllPlayersReady && // are all the clients created + ready?
Player.LocalPlayer != null && // and we exist as a local player
m_HasSentGameSceneReady == false; // and we haven't already sent the message
}
}
private bool AllPlayersReady
{
get
{
return m_ClientPlayerObjects.Count == numberOfPlayers;
}
}
// called from Player.OnStartClient
public void OnCreatedClientPlayerObject( Player clientPlayer )
{
m_ClientPlayerObjects.Add( clientPlayer );
if( ShouldSendGameSceneReady )
{
SendLocalPlayerGameSceneReady();
}
}
// called from Player.OnStartLocalPlayer
public void OnCreatedLocalPlayerObject( Player localPlayer )
{
if( ShouldSendGameSceneReady )
{
SendLocalPlayerGameSceneReady();
}
}
private void SendLocalPlayerGameSceneReady()
{
m_HasSentGameSceneReady = true;
// send your game scene ready message to the server here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment