LOAD LEVEL

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

Answers

  • Tobias
    Tobias admin
    edited July 28

    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.

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

  • Tobias
    Tobias admin

    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"?

  • 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

  • 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
    Mehmet61
    edited August 1

    I wıll try . Thank You very much

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

  • 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.

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

  • 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...