I'm new to using SmartFoxServer and I would like to know what is the best way to setup an "easy" multiplayer game.
So far, using tutorials from the Internet (and a little bit of my thinking too ) I was able to connect several users in a room correctly (everybody "sees" everybody). But all the users have the same "pre-defined" avatar.
Now I would like users to be seen through their "real" avatar, not a unique pre-defined one.
Ok, so I though the best way to do that is by creating a "uservariable" storing the id of the used avatar.
So I wrote this little code :
Code: Select all
private void OnJoinRoom(Room room) {
GameObject avatarSelectorObject = GameObject.Find("AvatarSelector");
AvatarIdentifier avatarSelectorScript = avatarSelectorObject.GetComponent<AvatarIdentifier>();
// add custom user avatar id
Hashtable uVars = new Hashtable();
uVars.Add("avatar", avatarSelectorScript.selectedAvatar);
smartFoxClient.SetUserVariables(uVars);
But if I do :
Code: Select all
private void SpawnRemotePlayer(User user) {
int avatarIndex = (int)user.GetVariable("avatar");
}
I get an error message saying that avatarIndex is null.
Can somebody help me? Thanks.
Edit : Actually, it seems the user variable is correctly created and set. The problem is when I try to use it, as it is defined as an "object" I can't cast it to int.