Skip to content
Snippets Groups Projects
Commit 42a8a004 authored by William G. Tresselt's avatar William G. Tresselt
Browse files

Fixed bug for colored ground

parent 38cce0f0
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ GameObject: ...@@ -15,7 +15,7 @@ GameObject:
- component: {fileID: 7364672847754121426} - component: {fileID: 7364672847754121426}
m_Layer: 0 m_Layer: 0
m_Name: GroundBlue m_Name: GroundBlue
m_TagString: GroundBlue m_TagString: GroundColored
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
......
...@@ -15,7 +15,7 @@ GameObject: ...@@ -15,7 +15,7 @@ GameObject:
- component: {fileID: 7364672847754121426} - component: {fileID: 7364672847754121426}
m_Layer: 0 m_Layer: 0
m_Name: GroundGreen m_Name: GroundGreen
m_TagString: GroundGreen m_TagString: GroundColored
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
......
...@@ -15,7 +15,7 @@ GameObject: ...@@ -15,7 +15,7 @@ GameObject:
- component: {fileID: 7364672847754121426} - component: {fileID: 7364672847754121426}
m_Layer: 0 m_Layer: 0
m_Name: GroundRed m_Name: GroundRed
m_TagString: GroundRed m_TagString: GroundColored
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
......
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
public class ColorChanger : MonoBehaviour public class ColorChanger : MonoBehaviour
...@@ -7,11 +9,7 @@ public class ColorChanger : MonoBehaviour ...@@ -7,11 +9,7 @@ public class ColorChanger : MonoBehaviour
private Renderer userrenderer; private Renderer userrenderer;
private Material material; private Material material;
private List<ColorSubscriber> colorSubscribers = new List<ColorSubscriber>(); private GameObject[] groundColored;
private GameObject[] ground;
private GameObject[] groundRed;
private GameObject[] groundGreen;
private GameObject[] groundBlue;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
...@@ -19,10 +17,7 @@ public class ColorChanger : MonoBehaviour ...@@ -19,10 +17,7 @@ public class ColorChanger : MonoBehaviour
userrenderer = GetComponent<Renderer>(); userrenderer = GetComponent<Renderer>();
material = userrenderer.material; material = userrenderer.material;
if (ground == null) ground = GameObject.FindGameObjectsWithTag("Ground"); if (groundColored == null) groundColored = GameObject.FindGameObjectsWithTag("GroundColored");
if (groundRed == null) groundRed = GameObject.FindGameObjectsWithTag("GroundRed");
if (groundGreen == null) groundGreen = GameObject.FindGameObjectsWithTag("GroundGreen");
if (groundBlue == null) groundBlue = GameObject.FindGameObjectsWithTag("GroundBlue");
} }
// Update is called once per frame // Update is called once per frame
...@@ -31,7 +26,7 @@ public class ColorChanger : MonoBehaviour ...@@ -31,7 +26,7 @@ public class ColorChanger : MonoBehaviour
if (Input.GetButtonDown(KeyCode.Alpha1.ToString())) if (Input.GetButtonDown(KeyCode.Alpha1.ToString()))
{ {
material.color = Color.red; material.color = Color.red;
foreach (GameObject g in groundRed) foreach (GameObject g in groundColored)
{ {
if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.red); if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.red);
} }
...@@ -39,7 +34,7 @@ public class ColorChanger : MonoBehaviour ...@@ -39,7 +34,7 @@ public class ColorChanger : MonoBehaviour
if (Input.GetButtonDown(KeyCode.Alpha2.ToString())) if (Input.GetButtonDown(KeyCode.Alpha2.ToString()))
{ {
material.color = Color.green; material.color = Color.green;
foreach (GameObject g in groundGreen) foreach (GameObject g in groundColored)
{ {
if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.green); if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.green);
} }
...@@ -47,10 +42,18 @@ public class ColorChanger : MonoBehaviour ...@@ -47,10 +42,18 @@ public class ColorChanger : MonoBehaviour
if (Input.GetButtonDown(KeyCode.Alpha3.ToString())) if (Input.GetButtonDown(KeyCode.Alpha3.ToString()))
{ {
material.color = Color.blue; material.color = Color.blue;
foreach (GameObject g in groundBlue) foreach (GameObject g in groundColored)
{ {
if (g!=null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.blue); if (g!=null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.blue);
} }
} }
if(Input.GetButtonDown(KeyCode.R.ToString()))
{
material.color = Color.white;
foreach (GameObject g in groundColored)
{
if (g != null) g.GetComponent<ColorSubscriber>().notifyColorChange(Color.white);
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment