Open RisottoMan opened 1 day ago
Try to use raycast instead of using 2 foreach for players and platforms:
var tempDict = new List<KeyValuePair<Player, GameObject>>();
var occupiedPlatforms = new HashSet<GameObject>();
var players = Player.GetPlayers();
foreach (var player in players)
{
var playerPosition = player.Position;
if (Physics.Raycast(playerPosition, Vector3.down, out RaycastHit hit, Mathf.Infinity))
{
var platform = hit.collider.gameObject;
if (Platforms.Contains(platform) && !occupiedPlatforms.Contains(platform))
{
platform.GetComponent<PrimitiveObjectToy>().NetworkMaterialColor = Color.red;
occupiedPlatforms.Add(platform);
tempDict.Add(new KeyValuePair<Player, GameObject>(player, platform));
}
}
}
While the mini-game is running on a large number of servers and on a large number of players, the game may freeze and not end.