From 3ff87c00066f0559636a517a298b7448aed2abd8 Mon Sep 17 00:00:00 2001 From: JWS Date: Wed, 2 Feb 2022 17:39:39 -0600 Subject: [PATCH] fix for color selection --- Assets/RocketSphere.cs | 21 +++++++++++++++------ ProjectSettings/EditorBuildSettings.asset | Bin 4336 -> 4336 bytes 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Assets/RocketSphere.cs b/Assets/RocketSphere.cs index f474f85..3715f2e 100644 --- a/Assets/RocketSphere.cs +++ b/Assets/RocketSphere.cs @@ -40,7 +40,7 @@ public class RocketSphere : NetworkBehaviour public GameObject explosionPrefab; Rigidbody rb; [SyncVar] Color RocketColor = Color.white; - [SyncVar] float hue = 2.0f; + float hue = 2.0f; [SyncVar] bool visible = false; [SyncVar] Quaternion rot2Save = Quaternion.identity; @@ -72,7 +72,9 @@ public override void OnStartServer() int count = 0; for (int i = 0; i < players.Length; i++) { - Debug.Log("Player " + i + " hue " + players[i].hue); + float otherplayerhue = players[i].hue; + + Debug.Log("Other Player " + i + " hue " + otherplayerhue); if (players[i] == this) { @@ -90,12 +92,19 @@ public override void OnStartServer() // difference check must be small enough that we have enough colors for all players. // if max player count is increased from 4, this value should be reassessed // this could be an infinte check otherwise, might want a failsafe escape - if ( (Mathf.Abs(hue - players[i].hue) < 0.2f) && - (Mathf.Abs(hue - players[i].hue + 1.0f) < 0.2f) && - (Mathf.Abs(hue - players[i].hue - 1.0f) < 0.2f) && + + Debug.Log("diffs " + + Mathf.Abs(hue - otherplayerhue) + " " + + Mathf.Abs(hue - otherplayerhue + 1.0f) + " " + + Mathf.Abs(hue - otherplayerhue - 1.0f)); + const float colorhuediffmax = 0.10f; + + if ( ((Mathf.Abs(hue - otherplayerhue) < colorhuediffmax) || + (Mathf.Abs(hue - otherplayerhue + 1.0f) < colorhuediffmax) || + (Mathf.Abs(hue - otherplayerhue - 1.0f) < colorhuediffmax)) && (players[i] != this)) { - Debug.Log("Player " + i + " hue " + players[i].hue + " too close " + hue); + Debug.Log("Player " + i + " hue " + players[i].hue + " too close to hue " + hue); // generate a new hue if it is too close to this other players color hue = Random.Range(0.0f, 1.0f); diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 627bb4c6c59d60c36df302f7757b94db2f3f635c..637ae4fcf5635af77ef4306d06a4e9b8a1f05b39 100644 GIT binary patch delta 38 ucmeyM_(5?)G>hP3=1g|(h2_rO`NxGkdgpL6Z7yV)%ssh*g>^EEz#9M+Zw-Y2 delta 38 ucmeyM_(5?)G>c%uUdPtOmnB^qZ!Plp6l7@0w7HOFGWX;L7S_ou0&f6BJ`ZC6