I'm not sure why I get an error with this code.

When i click connect it says:
ConnectUsingSettings() failed. Can only connect while in state 'Disconnected'. Current state: Connected
UnityEngine.Debug:LogWarning(Object)
PhotonNetwork:ConnectUsingSettings(String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1165)
GameManager:Connect() (at Assets/Scripts/GameManager.cs:12)
GameManager:OnGUI() (at Assets/Scripts/GameManager.cs:48)

My code says:
using UnityEngine; using System.Collections; public class GameManager : Photon.MonoBehaviour { public GameObject[] redSpawns; public GameObject[] blueSpawns; public int state = 0; void Connect () { PhotonNetwork.ConnectUsingSettings ("V1.0"); } void OnJoinedLobby() { state = 1; } void OnPhotonRandomJoinedFailed() { PhotonNetwork.CreateRoom (null); } void OnJoinedRoom() { state = 2; } void Start () { } void Update () { } void OnGUI () { switch (state) { case 0: //STARTING SCREEN if (GUI.Button(new Rect(10, 10, 100, 30), "Connect")) { Connect (); } break; case 1: //CONNECTED TO SERVER GUI.Label(new Rect(10, 40, 100, 30), "Connected"); if (GUI.Button(new Rect(10, 10, 100, 30), "Search")) { PhotonNetwork.JoinRandomRoom(); } break; case 2: //CHANPION SELECT GUI.Label(new Rect(10, 40, 200, 30), "Select Your Champion"); if (GUI.Button(new Rect(70, 10, 100, 30), "Mojo")) { Spawn(0, "Mojo"); } break; case 3: //IN GAME break; } } void Spawn(int team, string character) { state = 3; Debug.Log("You are on team..." + team + ". And are playing as " + character); } }

Please use the code above and edit it to make it work in your answer please!

Answers

  • ConnectUsingSettings() failed. Can only connect while in state 'Disconnected'. Current state: Connected occurs when you try to connect to photon when you are already connected . you need disconnect from photon first