C# in Unity

profilelldhl
changeColor.cs

using System.Collections; using System.Collections.Generic; using UnityEngine; public class changeColor : MonoBehaviour { Vector3 light_p = new Vector3(0, 0, 5); Vector3 camera = new Vector3(1, 1, 5); Color color_light = new Color(0.8f, 0.8f, 0.8f); Color color_ambient = new Color(0.9f, 0.9f, 0.9f); Color color_phong = new Color(0.2f, 0.2f, 0.2f); Color color_white = new Color(0.5f, 0.5f, 0.5f); Color color_gold = new Color(0.9f * 0.8f, 0.7f * 0.8f, 0.1f * 0.8f); Color color_obj = new Color(0.5f, 0.5f, 0.5f); void Start() { Mesh mesh = GetComponent<MeshFilter>().mesh; //this function split the vertex for each triangles //ex. 545 vertex and 1000 triangles will become 3000 vertex and 1000 triangles SplitMesh(mesh); // to set colors SetColors(mesh); } void Update() { transform.Rotate(new Vector3(0, 1, 0)); } void SplitMesh(Mesh mesh) { int[] triangles = mesh.triangles; Vector3[] verts = mesh.vertices; Vector3[] newVerts; int n = triangles.Length; newVerts = new Vector3[n]; for (int i = 0; i < n; i++) { newVerts[i] = verts[triangles[i]]; triangles[i] = i; } mesh.vertices = newVerts; mesh.triangles = triangles; } void SetColors(Mesh mesh) { Color[] colors = new Color[mesh.vertexCount]; for (int i = 0; i < colors.Length; i += 3) { colors[i] = new Color(0,1,0); colors[i + 1] = new Color(0, 1, 0); colors[i + 2] = new Color(0, 1, 0); } mesh.colors = colors; } }