Skip to content

Instantly share code, notes, and snippets.

@FVSHaLuan
Last active October 25, 2015 07:42
Show Gist options
  • Save FVSHaLuan/2c00c549188174dcf83e to your computer and use it in GitHub Desktop.
Save FVSHaLuan/2c00c549188174dcf83e to your computer and use it in GitHub Desktop.
**Function: creating a mesh data for god's sake
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
[ExecuteInEditMode]
public class DumbMesh : MonoBehaviour
{
void Start()
{
GenerateMesh();
}
void GenerateMesh()
{
Mesh mesh = GetComponent<MeshFilter>().sharedMesh;
if (mesh == null)
{
mesh = new Mesh();
GetComponent<MeshFilter>().sharedMesh = mesh;
}
mesh.Clear();
mesh.vertices = new Vector3[]
{
new Vector3(-1,-1,0),
new Vector3(1,-1,0),
new Vector3(1,1,0),
new Vector3(-1,1,0),
};
mesh.triangles = new int[]
{
2,1,0,
3,2,0
};
mesh.uv = new Vector2[]
{
new Vector3(0,0,0),
new Vector3(1,0,0),
new Vector3(1,1,0),
new Vector3(0,1,0),
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment