End Game a multiplayer Game

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

End Game a multiplayer Game

BlackShadow972
2020-07-23 15:57:28

Hello, I'm beginer with Photon and I am developing a multiplayer Pong game. I managed to develop the game and make the conditions for victory. But I'm looking

  1. How to end a game properly by removing all players from a room and returning to the main menu (the player is disconnected from the server)

  2. Return to the lobby while remaining connected to the master server, ready to search for a new game.

Can you help me perform the correct method please ?

Comments

BlackShadow972
2020-07-25 14:15:37

This is my code and it function well, but i have a message issue at the line ( PhotonNetwork.LeaveRoom())
In my debug console it say: Operation LeaveRoom(254) not called beacause client is not connected or not ready yet, client state: leaving

    void Update()  
    {  
        // Win condition  
        if (scoreP1.score == scoreVictoire)  
        {  
            textVictoire.text = "Player 1 win";  
            finDePartie = true;  
            StartCoroutine(EndGame());

        }  
        else if (scoreP2.score == scoreVictoire)  
        {  
            textVictoire.text = "Player 2 win";  
            finDePartie = true;  
            StartCoroutine(EndGame());          
        }

        // lorsque la balle n'est plus en jeux et la partie n'est pas fini  
        if (ballEnJeu == false && finDePartie == false)  
            {  
                SpawnBall();  
                ballEnJeu = true;  
            }  
    }

    public void SpawnBall()  
    {  
        GameObject ball = PhotonNetwork.Instantiate("BallOnline", spawnBallPoint.transform.position, Quaternion.identity);  
        ballEnJeu = true;  
        finDePartie = false;  
    }

    // à la deconnexion de la salle, changement de scene et retour au menu principal  
    public override void OnDisconnected(DisconnectCause cause)  
    {  
        Debug.Log("cause de la deconnexion: " + cause.ToString());  
        UnityEngine.SceneManagement.SceneManager.LoadScene(0);<s></s>   
    }

    public override void OnLeftRoom()  
    {  
        PhotonNetwork.Disconnect();  
    }

    private IEnumerator EndGame()  
    {  
        float timer = 5.0f;

        while (timer > 0.0f)  
        {  
            yield return new WaitForEndOfFrame();

            timer -= Time.deltaTime;  
            Debug.Log(timer);  
        }

        PhotonNetwork.LeaveRoom();  
        Debug.Log("sortie de chambre");  
    }  
}
Back to top