Photon Multiplayer Help

I’m building a 1v1 Multiplayer game and I’ve reached a point where when the Master client first looks for a battle it doesn’t fully load the scene and the other player does. But if the nonMaster client looks first for a battle they both load correctly with some minor bugs which I intend to fix later after I get both cases working.

Here is the button start looking for battle

public void StartBattle()
        {
            foreach (AccountStats acc in LobbyManagerNew.Players)
            {
                if (acc.me)
                {
                    acc.isLooking = true;
                }    
            }
        }

Here is where it looks for battle

public void Update()
        {
                players = GetPlayers();
                if (myplayer.isLooking)
                {
                    if (GameConstants.timedOut >= 0)
                    {
                        myplayer.count = GameConstants.timedOut;
                        GameConstants.timedOut -= Time.deltaTime;

                        AccountStats acc = GameFunctions.FoundPlayer(myplayer.mmrRating, players.ToArray());
                        if (acc != null)
                        {
                            PhotonNetwork.LoadLevel(2);
                        }
                    }
                    else
                    {
                        myplayer.isLooking = false;
                        myplayer.count = 0;
                    }
                }           
        }

        List<AccountStats> GetPlayers()
            {
                List<AccountStats> gotPlayers = new List<AccountStats>();
                GameObject[] gos = GameObject.FindGameObjectsWithTag(GameConstants.photonPlayer);
                foreach (GameObject go in gos)
                {
                    gotPlayers.Add(go.GetComponent<AccountStats>());
                }
                return gotPlayers;
            }

Here is how its finding another player

public static AccountStats FoundPlayer(int mmr, AccountStats[] accountStats)
        {
            foreach (AccountStats acc in accountStats)
            {
                if (acc.isLooking && !acc.me)
                {
                    if (mmr <= acc.mmrRating + 50 && mmr >= acc.mmrRating - 50)
                    {
                        return acc;
                    }
                }
            }
            return null;
        }

Fixed (not a good fix but it worked)

If anyone was following i fixed it with an RPC! Not the best fix but my focus its to get the prototype working!

The first load is the master Client.

The second load is the master Client.

Privacy & Terms