Universally challenged fixed
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user