- Home /
Question by
zak666 · Aug 06, 2019 at 08:37 PM ·
photondisconnect
Cannot connect to photon after II disconnect
OK so works fine when I first load my Game, however when i Disconnected from server and return to my home-scene to launch a new game after I finish my game using PhotonNetwork.Disconnect(); when i load my PhotonConnect scene, nothing happens, yet it works when I load it the first time?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class photonConnectonNewsystem : MonoBehaviourPunCallbacks, IInRoomCallbacks
{
public PhotonView PhotonViewPv;
private Player[] ConnectedPlayers;
public int MyPhotonPlayers;
public bool LoadExtraScpace;
public bool LoadSystem;
public string systemToEnter;
public GameObject Account;
public LastRoomEntered LastRoomEnteredCS;
private void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
public void Start()
{
Account = GameObject.FindGameObjectWithTag("Account");
LastRoomEnteredCS = Account.GetComponent<LastRoomEntered > ();
systemToEnter = LastRoomEnteredCS.NextRoom;
PhotonViewPv = GetComponent<PhotonView>();
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
base.OnConnectedToMaster();
PhotonNetwork.JoinRoom(LastRoomEnteredCS.NextRoom);
}
public override void OnJoinRoomFailed(short returnCode, string message)
{
base.OnJoinRandomFailed(returnCode, message);
Debug.Log("Failed to join random Room...");
CreateRoomConnect();
}
void CreateRoomConnect()
{
RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 100 };
PhotonNetwork.CreateRoom(LastRoomEnteredCS.NextRoom);
}
public override void OnCreateRoomFailed(short returnCode, string message)
{
base.OnCreateRoomFailed(returnCode, message);
CreateRoomConnect();
}
}
Comment
you are aware that since you use Don't destroy on load
there will be 2 photonConnectonNewsystem
objects when you load the scene the second time?
I am deleting the object with another script and reloading the start room.