Hello there!
I have a problem when switching scenes.
So, when I click the button to switch scenes my game completely freezes (and does not unfreeze) I have searched everywhere for a solution and tried everything I know about but nothing seems to work.
I hope someone can help
the code I use for switching scenes (and to spawn the player in) :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.SceneManagement;
using Photon.Pun;
using Unity.VisualScripting;
public class RoomManager : MonoBehaviourPunCallbacks
{
public static RoomManager Instance;
private void Awake()
{
if (Instance)
{
Destroy(gameObject);
return;
}
Instance = this;
return;
}
private void Start()
{
PhotonNetwork.AutomaticallySyncScene = true;
}
private void Update()
{
if (Input.GetKey(KeyCode.P))
{
StartGame();
}
}
public override void OnEnable()
{
base.OnEnable();
SceneManager.sceneLoaded += OnSceneLoaded;
return;
}
public override void OnDisable()
{
base.OnDisable();
SceneManager.sceneLoaded -= OnSceneLoaded;
return;
}
void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
Time.timeScale = 1f;
if (scene.buildIndex == 1)
{
StartCoroutine(SpawnPlayerManager());
return;
}
}
public void StartGame()
{
SceneManager.LoadScene("MainMaze");
}
IEnumerator SpawnPlayerManager()
{
yield return new WaitForSeconds(3);
PhotonNetwork.Instantiate(Path.Combine("PhotonPrefabs", "PlayerManager"), Vector3.zero, Quaternion.identity);
}
}