- Home /
Photon cannot create room No room name (when I have one....)
Hey guys for some reason it says i don't have a rooName when it iss clearly defined....
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
public class GameConnectClassic : Photon.MonoBehaviour {
public int Team = 0;
public int Team2 = 0;
public int Team1 = 0;
public bool pregame;
public string roomName = "ClassicGame";
public virtual void Start()
{
PhotonNetwork.autoJoinLobby = true; // we join randomly. always. no need to join a lobby to get the list of rooms.
PhotonNetwork.ConnectUsingSettings("0.1");
}
public void OnConnectedToMaster()
{
Debug.Log("OnConnectedToMaster() was called by PUN. Now this client is connected and could join a room. Calling: PhotonNetwork.JoinRandomRoom();");
PhotonNetwork.JoinRandomRoom();
}
public void OnJoinedLobby()
{
Debug.Log("OnJoinedLobby(). This client is connected and does get a room-list, which gets stored as PhotonNetwork.GetRoomList(). This script now calls: PhotonNetwork.JoinRandomRoom();");
PhotonNetwork.JoinRandomRoom();
RoomOptions roomOptions = new RoomOptions () { isVisible = true, maxPlayers = 3 };
PhotonNetwork.JoinOrCreateRoom (roomName, roomOptions, TypedLobby.Default);
}
public void OnPhotonRandomJoinFailed()
{
RoomOptions roomOptions = new RoomOptions () { isVisible = true, maxPlayers = 1 };
Debug.Log("OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);");
PhotonNetwork.JoinOrCreateRoom (roomName, roomOptions, TypedLobby.Default);
}
public void OnJoinedRoom(){
Debug.Log ("JoinnedTheGame");
if (Team1 < 3) {
Team1 += 1;
Team = 1;
photonView.RPC ("JoinTeam1", PhotonTargets.OthersBuffered);
} else {
Team2 += 1;
Team = 2;
photonView.RPC ("JoinTeam2", PhotonTargets.OthersBuffered);
}
}
// Update is called once per frame
void Update () {
if (PhotonNetwork.countOfPlayers == 1 && pregame == true) {
pregame = false;
Application.LoadLevel ("Classic");
}
}
}
Answer by ChristianSimon · Oct 02, 2017 at 11:52 AM
Hi,
in the OnJoinedLobby callback there are two attempts trying to join a room. This won't work. What you can do instead is to call JoinRandomRoom() and see if this works by implementing the OnPhotonRandomJoinFailed() which you already have. If joining a random room succeeded you are already done, if it fails this callback is called and you have to create a new room by either using JoinOrCreateRoom(...) or CreateRoom(...).
You can also remove the JoinRandomRoom() call from the OnConnectedToMaster callback, because you join the lobby afterwards and can continue as explained before.
Your answer
Follow this Question
Related Questions
Photon Networking create room issue 1 Answer
Photon Networking and Team creation. 3 Answers
Photon Cannot sync animations 2 Answers
OnPhotonSerializeView streams effecting eachother. 0 Answers
Network RPC find sender gameobject 2 Answers