connection problem
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
connection problem
hellriderz
2015-08-05 12:59:06
ConnectUsingSettings() failed. Can only connect while in state 'Disconnected'. Current state: Connecting
here is my code
using UnityEngine;
using System.Collections;
public class ConnectAndCreate : Photon.PunBehaviour
{
const string VERSION = "0.1";
// Connect to network
void Start ()
{
// connect to Phonton Network
PhotonNetwork.ConnectUsingSettings(VERSION);
// turn Scene Sync on
PhotonNetwork.automaticallySyncScene = true;
}
public void OnGUI()
{
// Debug info on connection status. Remove Later.
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
}
// try join a random room.
public override void OnJoinedLobby()
{
PhotonNetwork.JoinRandomRoom();
}
// when failed to join random room create new room max players 3.
void OnPhotonRandomJoinFailed()
{
Debug.Log("No rooms available, creating new one.");
// (room name, not sure, not sure, max players). set room name to null for random name( to have more than 1 room created.
PhotonNetwork.CreateRoom(null, true, true, 3);
}
// when joined to a room check if max players are reached then send ROOM CREATOR into game.
public override void OnJoinedRoom()
{
if (PhotonNetwork.playerList.Length == 3) {
Debug.Log ("3 Players In Room Starting Level");
PhotonNetwork.LoadLevel ("Level01");
}
else if (PhotonNetwork.playerList.Length == 2) {
Debug.Log ("2 Players Waiting In Room");
}
else if (PhotonNetwork.playerList.Length == 1) {
Debug.Log ("1 Player Waiting In Room");
}
}
// when joined to a room check if max players are reached then send EVERY PLAYER into game(problem it does not send room creator).
void OnPhotonPlayerConnected(PhotonPlayer newPlayer){
if (PhotonNetwork.playerList.Length == 3) {
Debug.Log ("3 Players In Room Starting Level");
PhotonNetwork.LoadLevel ("Level01");
}
else if (PhotonNetwork.playerList.Length == 2) {
Debug.Log ("2 Players Waiting In Room");
}
else if (PhotonNetwork.playerList.Length == 1) {
Debug.Log ("1 Player Waiting In Room");
}
}
}
this code was working yesterday with 4 differnt clients and now it is not orking it seems to be getting stuck on the connection settings(i have tried redoing my appID still no fix) iv tried a new project and still nothing. is there any one that can help a beginner
Comments
"ConnectUsingSettings() failed. Can only connect while in state 'Disconnected'. Current state: Connecting"
This means you can't call ConnectUsingSettings() because you are already connecting. This should be one of the first checks it does, so even if you call ConnectUsingSettings() many times in a row, it should connect at some point.
Make sure you don't have a second PhotonServerSettings file in the project. There can be duplicates.
What's in the console logs?
Are you testing on a device?
LOL! Sorry I forgot to u that in my build settings
I am having the same problem in school but not at home. Do you know why?
Back to top