Created
May 1, 2016 06:25
-
-
Save ilkinulas/ba3d6fb606a764e5b6637bac0374f6f0 to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using System.Collections.Generic; | |
[RequireComponent(typeof (MeshFilter))] | |
[RequireComponent(typeof (MeshRenderer))] | |
public class MeshGenerator : MonoBehaviour { | |
void Start () { | |
CreateCube (); | |
} | |
private void CreateCube () { | |
Vector3[] vertices = { | |
new Vector3 (0, 0, 0), | |
new Vector3 (1, 0, 0), | |
new Vector3 (1, 1, 0), | |
new Vector3 (0, 1, 0), | |
new Vector3 (0, 1, 1), | |
new Vector3 (1, 1, 1), | |
new Vector3 (1, 0, 1), | |
new Vector3 (0, 0, 1), | |
}; | |
int[] triangles = { | |
0, 2, 1, //face front | |
0, 3, 2, | |
2, 3, 4, //face top | |
2, 4, 5, | |
1, 2, 5, //face right | |
1, 5, 6, | |
0, 7, 4, //face left | |
0, 4, 3, | |
5, 4, 7, //face back | |
5, 7, 6, | |
0, 6, 7, //face bottom | |
0, 1, 6 | |
}; | |
Mesh mesh = GetComponent<MeshFilter> ().mesh; | |
mesh.Clear (); | |
mesh.vertices = vertices; | |
mesh.triangles = triangles; | |
mesh.Optimize (); | |
mesh.RecalculateNormals (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified version: https://gist.github.com/ajayyy/f7087ca6f37760f33bb9dba4b4c2d69f