LOAD LEVEL

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.

LOAD LEVEL

Mehmet61
2022-07-27 14:18:53

Hi,what I want to do is, when the room reaches a certain number,he chooses one of the several maps and opens it, when I do it, he just Decodes the room  the map is created for the player and it is not created for the other player.

the software I use;

using System.Collections;    
using System.Collections.Generic;    
using UnityEngine;    
using Photon.Realtime;    
using Photon.Pun;    
using UnityEngine.SceneManagement;    



       
  public class online : MonoBehaviourPunCallbacks    
  {    
  private int randomMap;    
    private void Awake()    
    {    
      PhotonNetwork.AutomaticallySyncScene = true;    
    }    
    void Start()    
    {    
      PhotonNetwork.ConnectUsingSettings();    
    }    
    public override void OnConnectedToMaster()    
    {    
      base.OnConnectedToMaster();    
      PhotonNetwork.JoinLobby();    
    }    
    public override void OnJoinedLobby()    
    {    
      PhotonNetwork.JoinOrCreateRoom("room", new RoomOptions { MaxPlayers = 20, IsOpen = true, IsVisible = false }, TypedLobby.Default);    
      base.OnJoinedLobby();    
    }    

    public override void OnJoinedRoom()    
    {    
      spawn();    
    if (PhotonNetwork.CountOfPlayers == 20)    
    {    
      randomMap = Random.Range(1, 10);    

      if (randomMap == 1)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 2)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 3)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 4)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 5)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 5)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 6)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 7)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 8)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    

      }    
      if (randomMap == 9)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    
      if (randomMap == 10)    
      {    
        PhotonNetwork.LoadLevel("Name from map");    
      }    

    }    
    }    

    public void spawn()    
    {    
      PhotonNetwork.Instantiate("car", Vector3.zero, Quaternion.identity, 0, null);    
    }    

  }    

I would appreciate it if you could tell me what I did wrong, thank you

Comments

Tobias
2022-07-28 15:11:49

Are you always loading "Name from map" or is that a modification you did for the forum?

When you load a new scene, Unity usually destroys all existing objects, unless marked with DontDestroyOnLoad(). So .. the object may be lost due to loading another scene.

Mehmet61
2022-07-28 19:26:47

thank you, but unfortunately, it didn't conflict, and the scene is still changing for one actor

Tobias
2022-07-29 14:44:11

All cases load "Name from map". Is it some scene that generates the map then? Or what do you mean with "just Decodes the room the map is created for the player"?

Mehmet61
2022-07-31 10:37:27

My target is to make a game like stumble guys and I want to do the multiplayer part of it with photon, but I couldn't do the sumble guys map change and I asked how do i do it

Tobias
2022-08-01 13:24:50

I see.

I think now I detected the issue: You are using OnJoinedRoom to call LoadLevel. The method OnJoinedRoom is only called on the client which just joined the room. It can load the scene but can't define which scene to load for everyone. That's reserved for the Master Client to decide.

Implement OnPlayerEnteredRoom instead and when the player count is 20, have the Master Client use PN.LoadLevel.

Mehmet61
2022-08-01 14:22:27

I wıll try . Thank You very much

Mehmet61
2022-08-06 10:56:58

Tobias 2022-08-01T13:24:50+00:00

I see.

I think now I detected the issue: You are using OnJoinedRoom to call LoadLevel. The method OnJoinedRoom is only called on the client which just joined the room. It can load the scene but can't define which scene to load for everyone. That's reserved for the Master Client to decide.

Implement OnPlayerEnteredRoom instead and when the player count is 20, have the Master Client use PN.LoadLevel.

can you give me an example because I can't find information about this topic

Tobias
2022-08-10 14:26:17

Essentially: Don't call PhotonNetwork.LoadLevel on clients that are not the Master Client. Skip this and let them follow the Master Client's lead.

Mehmet61
2022-08-11 13:14:57

But only if I do what you say .All things go to waste if the master client exits the game

Tobias
2022-08-12 12:01:00

I lost track where we are and how I can help, sorry.

I won't be around for almost 2 weeks, so I can't help for a while. Maybe you recap what's happening and what you want to happen instead...

Back to top