Skip to content

Instantly share code, notes, and snippets.

@davidejones
Created January 16, 2016 22:17
Show Gist options
  • Select an option

  • Save davidejones/d0720f4442b88ac2e56f to your computer and use it in GitHub Desktop.

Select an option

Save davidejones/d0720f4442b88ac2e56f to your computer and use it in GitHub Desktop.
unity3d create cube from script
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]
public class monkey : MonoBehaviour {
private Mesh mesh;
private List<Vector3> verts = new List<Vector3>(){
new Vector3(1f, 1f, -1f),
new Vector3(1f, -1f, -1f),
new Vector3(-1f, -1f, -1f),
new Vector3(-1f, 1f, -1f),
new Vector3(1f, 0.999999f, 1f),
new Vector3(0.999999f, -1f, 1f),
new Vector3(-1f, -1f, 1f),
new Vector3(-1f, 1f, 1f)
};
private List<Vector2> uvs = new List<Vector2> (){
};
private List<int> triangles = new List<int> (){
4,0,3,
4,3,7,
2,6,7,
2,7,3,
1,5,2,
5,6,2,
0,4,1,
4,5,1,
4,7,5,
7,6,5,
0,1,2,
0,2,3,
};
// Use this for initialization
void Start () {
//mesh = new Mesh();
mesh = GetComponent<MeshFilter>().mesh;
BuildMesh();
}
// Update is called once per frame
void Update () {
}
void BuildMesh ()
{
mesh.Clear ();
mesh.vertices = verts.ToArray();
mesh.triangles = triangles.ToArray();
//mesh.uv = uvs.ToArray();
mesh.Optimize ();
mesh.RecalculateNormals ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment