colored mesh made

have a single mesh that changes color based on keyboard input. needs to be  made for each cell and have color based on cell-value
This commit is contained in:
Simon O'Shea
2023-08-03 15:55:52 -04:00
parent 78c5f3689c
commit e6bd6d2c58
6 changed files with 150 additions and 10 deletions
@@ -13,7 +13,7 @@ public class Main : MonoBehaviour
void Start()
{
// Create world
world = new LogicGrid(5, 5, 10f, new Vector3(-10, -30));
world = new LogicGrid(5, 5, 10f, new Vector3(0, 0));
// Set default placement to Obstacle
placementValue = -1;
@@ -4,8 +4,12 @@ using UnityEngine;
public class MeshTesting : MonoBehaviour
{
Material m_Material;
void Start()
{
m_Material = GetComponent<Renderer>().material;
Debug.Log("Mesh Testing");
@@ -13,14 +17,24 @@ public class MeshTesting : MonoBehaviour
// Build required data-structures for triangle mesh
Vector3[] vertices = new Vector3[3];
Vector2[] uv = new Vector2[3];
int[] triangles = new int[3];
Vector3[] vertices = new Vector3[4];
Vector2[] uv = new Vector2[4];
int[] triangles = new int[6];
// Set vertices of polygon (triangle)
// Set vertices of polygon (2 triangles -> 1 quad)
vertices[0] = new Vector3( 0, 0);
vertices[1] = new Vector3( 0, 100);
vertices[2] = new Vector3(100, 100);
vertices[1] = new Vector3( 0, 10);
vertices[2] = new Vector3(10, 10);
vertices[3] = new Vector3(10, 0);
// UV index contains texture position that should match to vertex with same index
uv[0] = new Vector2(0, 0);
uv[1] = new Vector2(0, 1);
uv[2] = new Vector2(1, 1);
uv[3] = new Vector2(1, 0);
// Set order of indexes of vertices to draw polygon (v1 -> v2 -> v3 -> v1)
// Note: always set clockwise, otherwise mesh will be facing backwards
@@ -28,6 +42,9 @@ public class MeshTesting : MonoBehaviour
triangles[1] = 1;
triangles[2] = 2;
triangles[3] = 0;
triangles[4] = 2;
triangles[5] = 3;
mesh.vertices = vertices;
mesh.uv = uv;
@@ -36,4 +53,28 @@ public class MeshTesting : MonoBehaviour
GetComponent<MeshFilter>().mesh = mesh;
}
private void Update()
{
if(Input.GetKeyDown("1"))
{
Debug.Log("1");
m_Material.color = Color.white;
//m_Material.SetColor("_Color", Color.white);
}
if (Input.GetKeyDown("2"))
{
Debug.Log("2");
m_Material.color = Color.black;
//m_Material.SetColor("_Color", Color.white);
}
if (Input.GetKeyDown("3"))
{
Debug.Log("3");
m_Material.color = Color.green;
//m_Material.SetColor("_Color", Color.white);
}
}
}