From 6846c8fd20d982ed1acfe533c2557a490cc957d0 Mon Sep 17 00:00:00 2001 From: "William G. Tresselt" <williagt@stud.ntnu.no> Date: Wed, 26 Oct 2022 11:08:59 +0200 Subject: [PATCH] Fixed more bugs related to colors and made it more apparent which is activated --- ChromeEnigma/Assets/ColorSubscriber.cs | 9 +++++++-- ChromeEnigma/Assets/Scripts/ColorChanger.cs | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChromeEnigma/Assets/ColorSubscriber.cs b/ChromeEnigma/Assets/ColorSubscriber.cs index a72c34d..aa81e16 100644 --- a/ChromeEnigma/Assets/ColorSubscriber.cs +++ b/ChromeEnigma/Assets/ColorSubscriber.cs @@ -23,11 +23,16 @@ public class ColorSubscriber : MonoBehaviour public void notifyColorChange(Color c) { - if(c == material.color) + if (c.r == material.color.r && c.g == material.color.g && c.b == material.color.b) { Debug.Log("Subscriber got notified: " + c); mCollider.enabled = true; + material.color = new Color(c.r, c.g, c.b); + } + else + { + mCollider.enabled = false; + material.color = new Color(material.color.r, material.color.g, material.color.b, 0.1f); } - else mCollider.enabled = false; } } diff --git a/ChromeEnigma/Assets/Scripts/ColorChanger.cs b/ChromeEnigma/Assets/Scripts/ColorChanger.cs index d6f6d4f..2108e56 100644 --- a/ChromeEnigma/Assets/Scripts/ColorChanger.cs +++ b/ChromeEnigma/Assets/Scripts/ColorChanger.cs @@ -18,6 +18,10 @@ public class ColorChanger : MonoBehaviour material = userrenderer.material; if (groundColored == null) groundColored = GameObject.FindGameObjectsWithTag("GroundColored"); + foreach (GameObject g in groundColored) + { + if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(material.color); + } } // Update is called once per frame @@ -28,8 +32,7 @@ public class ColorChanger : MonoBehaviour material.color = Color.red; foreach (GameObject g in groundColored) { - if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.red); - } + if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.red); } } if (Input.GetButtonDown(KeyCode.Alpha2.ToString())) { -- GitLab