if (photonView.IsMine)
{
if (Keyboard.current.escapeKey.isPressed)
{
PhotonNetwork.Disconnect();
Application.Quit();
playerCount -= 1;
photonView.RPC("RPC_UpdatePlayerCount", RpcTarget.AllBuffered, playerCount);
}
}
[PunRPC]
public void RPC_UpdatePlayerCount(int playerCountSyncInt)
{
playerCount = playerCountSyncInt;
playerCountText.text = playerCount.ToString();
}
This is a bit of pseudo code but it should give you an idea of how this will work, the player count simply won’t update unless something has happened within the update function and the PhotonView is owned by the player. This means that you should be able to load the level without any issues I would have thought. I could completely agree though with being paranoid and using a master client check for the sake of it but Photon seems to be pretty solid with it’s network synchronisation I haven’t run into any problems as of yet.
I need to experiment with LoadLevel and the like but I’ve even been able to make a resource system using these methods just to show you it working with something more complicated and I’ve synced animations across the network as well.
public void ChopWood()
{
if (Mouse.current.rightButton.wasPressedThisFrame)
{
int ignorePlayerMaskint = (1 << 8);
LayerMask ignorePlayerMask = ~ignorePlayerMaskint;
Vector2 mouseScenePosition2D = playerCamera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
mouseScenePosition2D = new Vector2(mouseScenePosition2D.x, mouseScenePosition2D.y);
Vector2 playerEmptyPosition = new Vector2(playerEmpty.transform.position.x, playerEmpty.transform.position.y);
Vector2 mouseClickDirection = mouseScenePosition2D - playerEmptyPosition;
RaycastHit2D hit = Physics2D.Raycast(playerEmpty.transform.position, mouseClickDirection, 30, ignorePlayerMask);
if (hit)
{
if (hit.transform.tag == "Tree")
{
GameObject localTree = hit.transform.gameObject;
playerWood += 10;
localTree.GetComponent<TreeResource>().treeWood -= 10;
hit.transform.GetComponent<PhotonView>().RPC("RPC_UpdateTreeWood", RpcTarget.AllBuffered, localTree.GetComponent<TreeResource>().treeWood);
ChopWoodAnimations();
}
}
}
}
public void ChopWoodAnimations()
{
if (photonView.IsMine)
{
if (Mouse.current.rightButton.wasPressedThisFrame)
{
if (isFacingForward == true)
{
animator.SetTrigger("FrontAxeAnimation");
}
else
{
animator.ResetTrigger("FrontAxeAnimation");
}
}
if (Mouse.current.rightButton.wasPressedThisFrame)
{
if (isFacingBack == true)
{
animator.SetTrigger("BackAxeAnimation");
}
else
{
animator.ResetTrigger("BackAxeAnimation");
}
}
if (Mouse.current.rightButton.wasPressedThisFrame)
{
if (isFacingLeft == true)
{
animator.SetTrigger("LeftSideAxeAnimation");
}
else
{
animator.ResetTrigger("LeftSideAxeAnimation");
}
}
if (Mouse.current.rightButton.wasPressedThisFrame)
{
if (isFacingRight == true)
{
animator.SetTrigger("RightSideAxeAnimation");
}
else
{
animator.ResetTrigger("RightSideAxeAnimation");
}
}
}
}
All of this is just simply contained within the photonView.isMine command and it handles any potential conflicts for you which is why I wouldn’t have thought there would be any issues with loading and I think there’s even a build in command that the Photon devs have put in to let you wait for the clients to sync up the level load anyway.
Actually posting this up made me just noticed I duplicated the isMine command unnecessarily so I’ll have to have a look through that and fix some things. This should give you an idea of what I’m talking about though.
The way I would do it is if I were really paranoid maybe you could even implement a small spawn delay just to make sure that all the clients have caught up with each other so I could understand doing those kind of checks if you’re worried about latency.