Skip to content

Instantly share code, notes, and snippets.

@davepape
Created February 13, 2017 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davepape/d088b2161abe8e447c1f884ff1fcc974 to your computer and use it in GitHub Desktop.
Save davepape/d088b2161abe8e447c1f884ff1fcc974 to your computer and use it in GitHub Desktop.
#pragma strict
// Script that creates a Unity mesh with 2 triangles, with per-vertex colors
// Note that this requires the vertexColor shader (https://gist.github.com/davepape/6b74369986ff6324c47a)
// to also be in your project's assets
function Start () {
gameObject.AddComponent(MeshFilter);
gameObject.AddComponent(MeshRenderer);
GetComponent(Renderer).material = new Material(Shader.Find("Custom/Vertex Colored"));
var m = GetComponent(MeshFilter).mesh;
m.vertices = [ Vector3(-2,-2,0), Vector3(0,2,0), Vector3(2,-2,0), Vector3(0,-4,0)];
m.colors = [ Color(1,0,0), Color(0,1,0), Color(0,0,1), Color(1,1,1)];
m.triangles = [ 0, 1, 2, 0, 2, 3 ];
}
function Update () {
var m = GetComponent(MeshFilter).mesh;
var v = m.vertices;
v[0][0] = -2 + Mathf.Sin(Time.time);
m.vertices = v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment