Created
September 18, 2017 11:06
-
-
Save paulhayes/0184e35f44739d249440d7b777f46755 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
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public static class TriangleMesh { | |
| public static Mesh Create(float scale){ | |
| Mesh triangle = new Mesh(); | |
| Vector3[] vertexes = new Vector3[3]; | |
| Vector2[] uv = new Vector2[3]; | |
| for(int i=0;i<3;i++){ | |
| uv[i].x = vertexes[i].x = Mathf.Sin( i*2f*Mathf.PI/3f ); | |
| uv[i].y = vertexes[i].y = Mathf.Cos( i*2f*Mathf.PI/3f ); | |
| vertexes[i] *= scale; | |
| } | |
| int[] triangles = new int[]{ 0,1,2 }; | |
| triangle.vertices = vertexes; | |
| triangle.triangles = triangles; | |
| triangle.uv = uv; | |
| triangle.RecalculateNormals(); | |
| triangle.UploadMeshData(false); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment