Detecting players in room
How can i get the number of players connected to a room. Does a callback exists for player joined/left the room? Or a property on the room with the player count in the room?
RealtimeAvatarManager component. This component lives in the scene on the same game object as your Realtime instance and is responsible for instantiating an avatar prefab to represent the local player as well as keeping track of avatars that were instantiated for other players in the same room. RealtimeAvatarManager keeps track of all avatars in the room via the and properties. The property is a dictionary of all components stored under the that the avatar belongs to. You can use this to determine how many players are currently in a multiplayer space.RealtimeAvatarManager includes two events: avatarCreated and avatarDestroyed. You can use these events to be notified when players join and leave the room. Here's an example of how to use these events:localAvataravatarsavatarsRealtimeAvatarclientIDusing UnityEngine;
using Normal.Realtime;
public class MyAvatarManager : MonoBehaviour {
private RealtimeAvatarManager _manager;
private void Awake() {
_manager = GetComponent<RealtimeAvatarManager>();
_manager.avatarCreated += AvatarCreated;
_manager.avatarDestroyed += AvatarDestroyed;
}
private void AvatarCreated(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) {
// Avatar created!
}
private void AvatarDestroyed(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) {
// Avatar destroyed!
}
}