First I'm sorry for my English. I have a problem with the connection with photon, I have 2 scenes, the first with the menu and the second with the game. When I access the game scene, it connects to the photon and searches or creates a game. The first time I play everything runs smoothly but when I return to the menu and give play again stays in "Best region found in PlayerPrefs Connecting to: Eu" and does nothing more. I do not understand what I'm doing wrong. When I run it for the second time, the unity emulator lets me stop it but if I try to do something else it stops unity and I have to force it to close.
public void Connect()
{
Debug.Log("connect");
if (PhotonNetwork.connectionState == ConnectionState.Disconnected)
{
if (previousRoom != null) {
Debug.Log("con sala previa");
PhotonNetwork.ReconnectAndRejoin();
}
else
{
Debug.Log("sin sala previa"); //enter here at the second try
PhotonNetwork.ConnectUsingSettings(_gameVersion);
}
}
}
//exit game scene methods
private IEnumerator fadeToMenu()
{
if (local != null)
local.abandonar();
animandofadeimg = true;
fadeimg.transform.Find("Background").Find("reloj").GetComponent<Image>().enabled = false;
fadeimg.transform.Find("Background").Find("looking_for_game").GetComponent<Text>().enabled = false;
float alpha = fadeimg.GetComponent<CanvasGroup>().alpha;
while (alpha < 1)
{
alpha += Time.deltaTime;
if (alpha > 1)
alpha = 1;
fadeimg.GetComponent<CanvasGroup>().alpha = alpha;
yield return null;
}
animandofadeimg = false;
if (PhotonNetwork.inRoom)
{
Debug.Log("Manual Room Exit: Leaving room - " + PhotonNetwork.room.Name);
if (PhotonNetwork.isMasterClient)
{
PhotonNetwork.DestroyAll();
}
PhotonNetwork.Disconnect();
crearLog("desconecta de la sala");
}
loadMenu();
yield return null;
}
private void loadMenu()
{
if (!SceneManager.GetSceneByName("Menu").isLoaded)
{
SceneManager.LoadScene(1);
}
else
{
SceneManager.SetActiveScene(SceneManager.GetSceneByName("Menu"));
}
clearData();
}
private void clearData()
{
alpha = 0f;
preguntas = null;
if (sinresponder != null)
{
sinresponder.Clear();
sinresponder = null;
}
preguntaActual = null;
recompensa = 10;
TextoPregunta.text = "";
Puntos.text = "";
Tiempo.text = "";
Rivaltiempo.text = "";
RivalPuntos.text = "";
foreach (Button b in buttons)
{
b.GetComponentInChildren<Text>().text = "";
}
local = null;
rival = null;
escala = 0f;
crecimiento = true;
entrando = false;
saliendo = false;
ended = false;
ocultando = true;
animando = false;
ganado = true;
previousRoom = null;
foreach (GameObject go in FindObjectsOfType<GameObject>())
Destroy(go);
Destroy(gameObject);
}