- Home /
Question by
JITENDRA-RAJ · Oct 24, 2014 at 02:17 PM ·
photononline game
How to change offline to online mode in photon unity network
to come offline mode i have created (working fine but once i came offline then unable to come again online)
if(GUI.Button(new Rect (5, 115, 60,16),"", Offline_but.customStyles [0])){
change_online = Offline_but;
if (PhotonNetwork.connected) {
Debug.Log ("connected, so disconnect");
PhotonNetwork.Disconnect ();
}
PhotonNetwork.offlineMode = true;
GameManager.instance.player.CreateAvatar(new_playerPos, new_playerRot);
}
Then how to come online ???
if(GUI.Button(new Rect (5, 10, 60,16),"", Online_but.customStyles [0])) {
change_online = Online_but;
PhotonNetwork.offlineMode = false;
if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated) {
// Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
PhotonNetwork.ConnectUsingSettings("1.0");
}
GameManager.instance.player.CreateAvatar(new_playerPos, new_playerRot);
}
Comment
Best Answer
Answer by JITENDRA-RAJ · Nov 10, 2014 at 01:18 PM
Hi guys, I got solution. if any1 wants online/ offline mode see here.
void Connect() {
PhotonNetwork.ConnectUsingSettings("1.0");
}
void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom(null);
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");
GameManager.instance.player.CreateAvatar(new_playerPos, new_playerRot);
}
void OnGUI()
{
if(GUI.Button(new Rect (5, 115, 60,16),"", Offline_but.customStyles [0]))
{
if(!PhotonNetwork.offlineMode)
{
change_online = Offline_but;
if (PhotonNetwork.connected)
{
PhotonNetwork.Disconnect ();
}
PhotonNetwork.offlineMode = true;
PhotonNetwork.JoinRandomRoom();
}
}
if(GUI.Button(new Rect (5, 10, 60,16),"", Online_but.customStyles [0]))
{
if(PhotonNetwork.offlineMode)
{
change_online = Online_but;
PhotonNetwork.Destroy(GameManager.instance.player.character);
Connect();
}
}
}