[code=csharp]using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Draw AC ube. MDOE BY U3DCHINA.COM
/// </summary>
public class DrawACube : MonoBehaviour {
public GameObject cube;
// Use this for initialization
void Start () {
MeshFilter mf = cube.GetComponent<MeshFilter> ();
Mesh mesh = mf.mesh;
Vector3[] vertices = new Vector3[]{
//front
new Vector3(-1,1,1),
new Vector3(1,1,1),
new Vector3(-1,-1,1),
new Vector3(1,-1,1),
//top
new Vector3(-1,1,-1),
new Vector3(1,1,-1),
new Vector3(-1,1,1),
new Vector3(1,1,1),
//right
new Vector3(1,1,1),
new Vector3(1,1,-1),
new Vector3(1,-1,1),
new Vector3(1,-1,-1),
//left
new Vector3(-1,1,-1),
new Vector3(-1,1,1),
new Vector3(-1,-1,-1),
new Vector3(-1,-1,1),
//back
new Vector3(1,1,-1),
new Vector3(-1,1,-1),
new Vector3(1,-1,-1),
new Vector3(-1,-1,-1),
//bottom
new Vector3(-1,-1,1),
new Vector3(1,-1,1),
new Vector3(-1,-1,-1),
new Vector3(1,-1,-1)
};
int[] triangles = new int[]{
0,2,3,
3,1,0,
0+4,2+4,3+4,
3+4,1+4,0+4,
0+4*2,2+4*2,3+4*2,
3+4*2,1+4*2,0+4*2,
0+4*3,2+4*3,3+4*3,
3+4*3,1+4*3,0+4*3,
0+4*4,2+4*4,3+4*4,
3+4*4,1+4*4,0+4*4,
0+4*5,2+4*5,3+4*5,
3+4*5,1+4*5,0+4*5,
};
//UVs//
Vector2[] uvs = new Vector2[]
{
//front face// 0,0 is bottom left, 1,1 is top right//
new Vector2(0,1),
new Vector2(1,1),
new Vector2(0,0),
new Vector2(1,0),
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0),
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,1),
new Vector2(1,0)
};
mesh.Clear ();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.uv = uvs;
mesh.RecalculateNormals ();
}
// Update is called once per frame
void Update () {
}
}
[/code] |