Created
February 13, 2017 22:53
-
-
Save davepape/d088b2161abe8e447c1f884ff1fcc974 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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