Can't create a room and can't loadlevel!

Options
I joined the the server successfully.I have 2 buttons one to create a room and one to join an existing one.But when I click on the createRoom button nothing happens.Here's a sample of the code :
[code2=csharp]public class MultyPlayer : MonoBehaviour {

private float buttonXpos=Screen.width/2;
private float buttonYpos=Screen.height/2;
private bool joinedRoom;
private bool createdRoom;
private int numberPlayers;
private int numberRooms;

// Use this for initialization
void Start () {
PhotonNetwork.ConnectUsingSettings("v1.0");
PhotonNetwork.automaticallySyncScene=true;
}

// Update is called once per frame
void Update () {
if(PhotonNetwork.connected){
Debug.Log ("CONNECTED");
numberPlayers=PhotonNetwork.countOfPlayersOnMaster;
numberRooms=PhotonNetwork.countOfRooms;
}

}
void onJoinedLobby(){

if(createdRoom==true){
PhotonNetwork.CreateRoom(null ,true,true ,2);


}

if(joinedRoom == true){
PhotonNetwork.JoinRandomRoom();
PhotonNetwork.Instantiate("Sphere_prefab", new Vector3(0,0,0),
Quaternion.identity, 0);
}

}

public void OnCreatedRoom(){
PhotonNetwork.LoadLevel("Scene");

}

//User Interface
void OnGUI() {
if(GUI.Button(new Rect (buttonXpos , buttonYpos , 160 , 40) , "Connect to a room " + numberPlayers)){
joinedRoom=true;



}
if(GUI.Button (new Rect (buttonXpos , buttonYpos+40 , 160 , 40), "Create Game" )){
createdRoom=true;
}
GUI.Button(new Rect(buttonXpos,buttonYpos-80,120,40),""+ numberRooms);
}
}[/code2]

Comments

  • [Deleted User]
    Options
    Hi,

    OnGUI and OnJoinedLobby are not (necessary) called at the same moment. Move the Photon-related code from OnJoinedLobby directly to the buttons' handlers.
    if(joinedRoom == true){
    PhotonNetwork.JoinRandomRoom();
    PhotonNetwork.Instantiate("Sphere_prefab", new Vector3(0,0,0),
    Quaternion.identity, 0);
    }

    Do not call PhotonNetwork.Instantiate() immediately after PhotonNetwork.JoinRandomRoom(). Instantiate() works when the player joined. Joining doesn't happen right away, so it takes a bit of time before JoinRandomRoom() will finish its work.