Skip to content

Instantly share code, notes, and snippets.

@paulhayes
Created September 18, 2017 11:06
Show Gist options
  • Select an option

  • Save paulhayes/0184e35f44739d249440d7b777f46755 to your computer and use it in GitHub Desktop.

Select an option

Save paulhayes/0184e35f44739d249440d7b777f46755 to your computer and use it in GitHub Desktop.
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