Consider this Unity C# code snippet that manages a lobby's player count. What will be printed to the console?
using UnityEngine; using System.Collections.Generic; public class LobbyManager : MonoBehaviour { private List<string> players = new List<string>(); void Start() { players.Add("Alice"); players.Add("Bob"); players.Remove("Alice"); Debug.Log($"Players in lobby: {players.Count}"); } }
Think about how many players are added and removed before the count is printed.
Two players are added: Alice and Bob. Then Alice is removed. So only Bob remains, making the count 1.
Matchmaking helps players find games to join. Which option correctly describes its main purpose?
Think about why matchmaking is important for player experience.
Matchmaking aims to create fair and enjoyable games by grouping players with similar skill or location.
Look at this code snippet that tries to join a lobby. What causes the runtime error?
using UnityEngine; public class LobbyJoiner : MonoBehaviour { string lobbyId = null; void JoinLobby() { Debug.Log($"Joining lobby {lobbyId.ToUpper()}"); } void Start() { JoinLobby(); } }
Check what happens when you call a method on a null string.
Since lobbyId is null, calling ToUpper() on it causes a NullReferenceException at runtime.
You want to create a dictionary in C# that maps lobby names (strings) to player counts (integers). Which declaration is correct?
Remember the syntax for generic dictionaries in C#.
Option B correctly declares a dictionary with string keys and int values.
Given this code simulating players joining and leaving a lobby, what is the final count printed?
using System.Collections.Generic; using UnityEngine; public class MatchmakingSim : MonoBehaviour { List<string> players = new List<string>(); void Simulate() { players.Add("Anna"); players.Add("Ben"); players.Add("Cara"); players.RemoveAt(1); players.Add("Dan"); players.Remove("Anna"); Debug.Log($"Final players: {players.Count}"); } void Start() { Simulate(); } }
Track each add and remove step carefully.
Players added: Anna, Ben, Cara (3). RemoveAt(1) removes Ben (2 left). Add Dan (3). Remove Anna (2 left). Final count is 2.