fgamez1020
fgamez10206d ago

How to wait for four players are connected and then start the game?

How to wait for four players are connected and then start the game?
7 Replies
kapa.ai
kapa.ai6d ago
Hi @fgamez1020. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The provided knowledge sources do not contain specific information on how to wait for four players to connect before starting a game in NormalVR. However, you can typically achieve this by using a counter to track the number of connected players and starting the game when the counter reaches four. For more detailed information, I recommend checking the NormalVR documentation (https://normcore.io/documentation/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6d ago
<@1053407831916822528> kapa.ai is still learning and improving, please let us know how it did by reacting below
Mechabit
Mechabit6d ago
you can create a lobby and get players to join the lobby before loading the game scene you can create an actual lobby scene + room but if you use a custom data sync to tell players which scene to load you'll have to wait 0.1 seconds to make sure the server gets the data before you switch scenes or use something like a string dictionary callback alternatively you can use unity lobby and just have people join that before all jumping into the game scene + room
xulipa
xulipa6d ago
You can check how many players are in the room using clientID
fgamez1020
fgamez10202d ago
How Can I achieve that? @xulipa
Mechabit
Mechabitthis hour
he means if you are clientID 3 there's maybe 4 players in the room but that's not a guarantee as client IDs can be skipped or reused if someone leaves. A better option is to check the unity lobby player count or use avatar manager avatars list
xulipa
xulipa17h ago
if (UpdateAvatar._realtimeAvatarManager.avatars.Count > 3) This is how I'm using it. I got an UpdateAvatar script that has the realtime stuff in it. using System; using Normal.Realtime; using UnityEngine; public class UpdateAvatar : MonoBehaviour { public static int intClientID; public static event Action<bool> LocalPlayerConnected; public static RealtimeAvatarManager _realtimeAvatarManager; public static RealtimeAvatar _realtimeAvatar; public static Realtime _realtime; private void Awake() { _realtimeAvatarManager = GetComponent<RealtimeAvatarManager>(); _realtimeAvatarManager.avatarCreated += AvatarCreated; } private void OnEnable() { if (_realtime != null) _realtime.didDisconnectFromRoom += DidDisconnectFromRoom; _realtimeAvatarManager.avatarCreated += AvatarCreated; } private void OnDisable() { if (_realtime != null) _realtime.didDisconnectFromRoom -= DidDisconnectFromRoom; } private void AvatarCreated(RealtimeAvatarManager avatarManager, RealtimeAvatar avatar, bool isLocalAvatar) { if (isLocalAvatar) { _realtimeAvatar = avatar; LocalPlayerConnected?.Invoke(true); Realtime realtime = avatar.realtime; uint clientID = (uint)realtime.clientID; intClientID = (int)clientID; // Debug.Log("Your client ID:" + intClientID); } }