Scene Switching not working Correctly?

Hi,

I’m attempting to make an Arena Shooter, and I have all the ground work developed and implemented. (Utilizing Proton). However, the stupidest issue is getting me snagged.

I am trying to change the scene from the map to the title screen, however for some unknown reason it only works in game for either the first person to join a room or if the room only has one person.
I’ve attached the code for the pause menu and the joining/creating room functionality, any help would be greatly appreciated.

Pause Menu (Activated by a keypress in character, quit is triggered via a button on UI):
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using Photon.Pun;
using UnityEngine;
public class Pause : MonoBehaviour
{
public static bool paused = false;
public bool disconnecting = false;
public void TogglePause()
{
if (disconnecting) return;
paused = !paused;
transform.GetChild(0).gameObject.SetActive(paused);
Cursor.lockState = (paused) ? CursorLockMode.None : CursorLockMode.Confined;
Cursor.visible = paused;
}
public void Quit()
{
disconnecting = true;
PhotonNetwork.LeaveRoom();
SceneManager.LoadScene(0);
}
}

Starting/Joining Rooms (Relevant Functionality is bolded):
public class Launcher : MonoBehaviourPunCallbacks
{
public InputField usernameField;
public InputField roomnameField;
public Slider maxPlayersSlider;
public Text maxPlayersValue;
public static ProfileData myProfile = new ProfileData();
public GameObject tabMain;
public GameObject tabRooms;
public GameObject tabCreate;
public GameObject buttonRoom;
private List roomList;
public bool isConnected;
public Text connecting;
public Text connected;
public void Awake()
{
PhotonNetwork.AutomaticallySyncScene = true;
myProfile = Data.LoadProfile();
if (!string.IsNullOrEmpty(myProfile.username))
{
usernameField.text = myProfile.username;
}
Connect();
connecting.enabled = true;
connected.enabled = false;
}
public override void OnConnectedToMaster()
{
isConnected = true;
connecting.enabled = false;
connected.enabled = true;
PhotonNetwork.JoinLobby();
base.OnConnectedToMaster();
}
public override void OnJoinedRoom()
{
StartGame();
base.OnJoinedRoom();
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Create();
base.OnJoinRandomFailed(returnCode, message);
}
public void Connect()
{
PhotonNetwork.GameVersion = “0.0.0”;
PhotonNetwork.ConnectUsingSettings();
}
public void Join()
{
PhotonNetwork.JoinRandomRoom();
}
public void Create()
{
RoomOptions options = new RoomOptions();
options.MaxPlayers = (byte) maxPlayersSlider.value;
ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable();
properties.Add(“map”, 1);
options.CustomRoomProperties = properties;
PhotonNetwork.CreateRoom(roomnameField.text, options);
}
public void ChangeMap()
{
}
public void ChangeMaxPlayerSlider (float t_value)
{
maxPlayersValue.text = Mathf.RoundToInt(t_value).ToString();
}
public void TabCloseAll()
{
tabMain.SetActive(false);
tabRooms.SetActive(false);
tabCreate.SetActive(false);
}
public void TabOpenMain()
{
TabCloseAll();
tabMain.SetActive(true);
}
public void TabOpenRooms()
{
TabCloseAll();
tabRooms.SetActive(true);
}
public void TabOpenCreate()
{
TabCloseAll();
tabCreate.SetActive(true);
}
private void ClearRoomList()
{
Transform content = tabRooms.transform.Find(“Scroll View/Viewport/Content”);
foreach (Transform a in content) Destroy(a.gameObject);
}
public override void OnRoomListUpdate(List p_list)
{
roomList = p_list;
ClearRoomList();
Transform content = tabRooms.transform.Find(“Scroll View/Viewport/Content”);
foreach (RoomInfo a in roomList)
{
GameObject newRoomButton = Instantiate(buttonRoom, content) as GameObject;
newRoomButton.transform.Find(“Name”).GetComponent().text = a.Name;
newRoomButton.transform.Find(“Number”).GetComponent().text = a.PlayerCount + " / " + a.MaxPlayers;
newRoomButton.GetComponent().onClick.AddListener(delegate { JoinRoom(newRoomButton.transform); });
}
base.OnRoomListUpdate(roomList);
}
public void JoinRoom (Transform p_button)
{
string t_roomName = p_button.transform.Find(“Name”).GetComponent().text;
PhotonNetwork.JoinRoom(t_roomName);
}
public void StartGame()
{
if (string.IsNullOrEmpty(usernameField.text))
{
myProfile.username = "Guest " + Random.Range(100, 1000);
}
else
{
myProfile.username = usernameField.text;
}
if(PhotonNetwork.CurrentRoom.PlayerCount == 1)
{
Data.SaveProfile(myProfile);
PhotonNetwork.LoadLevel(1);
}
}
}

Welcome to the forums!

Take a look at how your code ended up. Would you want to try reading that? Follow instructions here:

Since your question is Photon specific but your title doesn’t mention that, you’re extremely unlikely to get the right people to open your thread. Plus it is posted in the wrong forum.

The Connected Games forum is where all the networking people are:

Oh, thanks. I haven’t posted here before so that’s a huge help!

1 Like