Created
September 29, 2015 04:44
-
-
Save davepape/6759de4f9ab9020b532e to your computer and use it in GitHub Desktop.
create a mesh with 2 triangles in Unity
This file contains 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 to create a mesh with 2 triangles. | |
// This should be attached to an empty GameObject. | |
// It assumes the existence of a custom shader to use the vertex colors | |
// without texture or lighting. | |
function Start () | |
{ | |
gameObject.AddComponent.<MeshFilter>(); | |
gameObject.AddComponent.<MeshRenderer>(); | |
var mat = new Material(Shader.Find("Custom/Vertex Colored")); | |
GetComponent.<Renderer>().material = mat; | |
var p0 : Vector3 = Vector3(-2,0,-1); | |
var p1 : Vector3 = Vector3(0,1,-1); | |
var p2 : Vector3 = Vector3(1,0,-1); | |
var p3 : Vector3 = Vector3(0,-1,-1); | |
var newVertices = [ p0, p1, p2, p3 ]; | |
var newColors = [ Color(1, 0, 0), Color(0,1,0), Color(0,0,1), Color(1,1,0) ]; | |
var newTriangles = [ 0, 1, 2, 0, 2, 3 ]; | |
var m = GetComponent.<MeshFilter>().mesh; | |
m.vertices = newVertices; | |
m.colors = newColors; | |
m.triangles = newTriangles; | |
} | |
function Update() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment