I've gotten my script to now connect to my server and login with a username. However, when I try to join a room (yes, the room exists), nothing happens. I get no errors, but OnJoinRoom doesn't run (I have a Debug.Log() inside it). I've been trying things for a few hours now and am completely stumped.
using UnityEngine;
using System;
using System.Collections;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
using SmartFoxClientAPI.Util;
public class NetworkController : MonoBehaviour {
private static SmartFoxClient smartFoxClient;
public static SmartFoxClient GetClient() {
return SmartFox.Connection;
}
private void SubscribeEvents() {
SFSEvent.onJoinRoom += OnJoinRoom;
SFSEvent.onUserEnterRoom += OnUserEnterRoom;
SFSEvent.onDebugMessage += OnJoinRoomError;
}
private void UnsubscribeEvents() {
SFSEvent.onJoinRoom -= OnJoinRoom;
SFSEvent.onUserEnterRoom -= OnUserEnterRoom;
}
// Use this for initialization
void Start () {
SubscribeEvents();
smartFoxClient = GetClient();
if (smartFoxClient==null) {
Debug.Log("can't find connection");
//Application.LoadLevel("Login");
return;
}
smartFoxClient.JoinRoom("The Garden");
}
public void OnJoinRoomError(string error) {
Debug.Log("room join error: " + error);
}
private void OnJoinRoom(Room room) {
//SendMessage("SpawnPlayers");
Debug.Log("Room " + room.GetName() + " joined successfully");
}
// This will be invoked when remote player enters our room
private void OnUserEnterRoom(int roomId, User user)
{
//We assume here that we have only one room - so no need to check roomId
SendMessage("UserEnterRoom", user);
}
}