Universally challenged fixed

This commit is contained in:
2025-12-07 23:15:32 +00:00
parent d2c18d2264
commit 4450d018b2
218 changed files with 65873 additions and 213 deletions

View File

@@ -173,6 +173,50 @@ public class PlayerManager : UdonSharpBehaviour
return "unassigned";
}
public void RandomizeAllPlayerTeams()
{
if (!Networking.IsOwner(gameObject)) return;
float half = currentPlayerIds.Length / 2f;
int redSlots = (int)half;
int blueSlots = currentPlayerIds.Length - redSlots;
int redAssigned = 0;
int blueAssigned = 0;
// Shuffle player IDs
int[] shuffledIds = new int[currentPlayerIds.Length];
System.Array.Copy(currentPlayerIds, shuffledIds, currentPlayerIds.Length);
ShuffleArray(shuffledIds);
// Assign teams based on shuffled order
for (int i = 0; i < shuffledIds.Length; i++)
{
string team = "unassigned";
if (redAssigned < redSlots)
{
team = "red";
redAssigned++;
}
else if (blueAssigned < blueSlots)
{
team = "blue";
blueAssigned++;
}
SetTeam(shuffledIds[i], team);
}
}
private void ShuffleArray(int[] array)
{
for (int i = array.Length - 1; i > 0; i--)
{
int randomIndex = UnityEngine.Random.Range(0, i + 1);
int temp = array[i];
array[i] = array[randomIndex];
array[randomIndex] = temp;
}
}
public string GetTeam(int playerId)
{
int index = GetPlayerIndex(playerId);