Hello there,
i'm searching for the recommended way to switch a room. So i already tryed out some things and got a result i'm not really happy with. I create a room when i join the game. Then i want to switch into another scene and create a new room with a properties room name, after joining the new room the other players still can see my character in the old one.
Here is my setup:
Joining into the world for the first time:
i'm searching for the recommended way to switch a room. So i already tryed out some things and got a result i'm not really happy with. I create a room when i join the game. Then i want to switch into another scene and create a new room with a properties room name, after joining the new room the other players still can see my character in the old one.
Here is my setup:
Joining into the world for the first time:
public class NetManager : Photon.MonoBehaviourAnd here is the script that gets called after switching into the new scene:
{
public virtual void Start()
{
PhotonNetwork.ConnectUsingSettings("v1.0");
}
public virtual void OnConnectedToMaster()
{
Debug.Log("OnConnectedToMaster() was called by PUN. Now this client is connected and could join a room. Calling: PhotonNetwork.JoinRandomRoom();");
PhotonNetwork.JoinRandomRoom();
}
public virtual void OnJoinedLobby()
{
Debug.Log("OnJoinedLobby(). This client is connected and does get a room-list, which gets stored as PhotonNetwork.GetRoomList(). This script now calls: PhotonNetwork.JoinRandomRoom();");
PhotonNetwork.JoinRandomRoom();
}
public virtual void OnPhotonRandomJoinFailed()
{
Debug.Log("OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);");
PhotonNetwork.CreateRoom(null, new RoomOptions() { MaxPlayers = 4 }, null);
}
public virtual void OnFailedToConnectToPhoton(DisconnectCause cause)
{
Debug.LogError("Cause: " + cause);
}
public void OnJoinedRoom()
{
Debug.Log("OnJoinedRoom() called by PUN. Now this client is in a room. From here on, your game would be running. For reference, all callbacks are listed in enum: PhotonNetworkingMessage");
if(GameObject.FindGameObjectWithTag("Player") == null) // Prevent from spawning the player again (because it's not getting destroyed on Load)
{
GameObject.Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);
}
// Create the player head
CreatePlayer();
}
public class NetManagerArena : Photon.MonoBehaviourHow the scene change gets called:
{
public virtual void Start()
{
PhotonNetwork.ConnectUsingSettings("v1.0");
}
public virtual void OnConnectedToMaster()
{
Debug.Log("OnConnectedToMaster() was called by PUN. No arena room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 2}, null);");
PhotonNetwork.JoinOrCreateRoom("arena", new RoomOptions() { MaxPlayers = 2 }, null);
}
public virtual void OnJoinedLobby()
{
PhotonNetwork.JoinRoom("arena");
}
public virtual void OnPhotonRandomJoinFailed()
{
Debug.Log("OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 2}, null);");
PhotonNetwork.CreateRoom("arena", new RoomOptions() { MaxPlayers = 2 }, null);
}
public virtual void OnFailedToConnectToPhoton(DisconnectCause cause)
{
Debug.LogError("Cause: " + cause);
}
public void OnJoinedRoom()
{
Debug.Log("OnJoinedRoom() called by PUN. Now this client is in a room. From here on, your game would be running. For reference, all callbacks are listed in enum: PhotonNetworkingMessage");
CreatePlayer();
}
private void ChangeScene()
{
PhotonNetwork.DestroyPlayerObjects(PhotonNetwork.player);
PhotonNetwork.LeaveRoom();
PhotonNetwork.Disconnect();
SceneManager.LoadScene("Arena");
}