Unity3D用代码方式创建一个Cube并对其进行操作用C#实现器
Unity3D⽤代码⽅式创建⼀个Cube并对其进⾏操作⽤C#实现器⾸先创建⼀个MakeCube脚本
在Awake函数中写以下代码
private void Awake()
{
感恩节说说var
pMeshFilter = gameObject.AddComponent(typeof(MeshFilter)) as MeshFilter;//⽹格过滤器
var
pMeshRender = gameObject.AddComponent(typeof(MeshRenderer)) as MeshRenderer;//⽹格渲染
var pMesh =
Mesh;    //⽹格过滤器的实例化的Mesh
Vector3[] pVector = new Vector3[36];
int[]
pTriangles = new int[pVector.Length];
//forword
pVector[0] = new
Vector3(-0.5f, -0.5f, -0.5f);
pVector[1] = new
Vector3(-0.5f, 0.5f, -0.5f);
pVector[2] = new
Vector3(0.5f, 0.5f, -0.5f);
pVector[3] = new
Vector3(-0.5f, -0.5f, -0.5f);
pVector[4] = new
Vector3(0.5f, 0.5f, -0.5f);
pVector[5] = new
Vector3(0.5f, -0.5f, -0.5f);
back
pVector[6] = new
Vector3(-0.5f, 0.5f, 0.5f);
pVector[7] = new
Vector3(-0.5f, -0.5f, 0.5f);如何学电脑
pVector[8] = new Vector3(0.5f,
0.5f, 0.5f);
pVector[9] = new
湖南专升本有哪些学校
Vector3(0.5f, 0.5f, 0.5f);
pVector[10] = new
Vector3(-0.5f, -0.5f, 0.5f);
pVector[11] = new
Vector3(0.5f, -0.5f, 0.5f);
//left
pVector[12] = new
Vector3(-0.5f, -0.5f, -0.5f);
蛇果与苹果的区别pVector[13] = new
Vector3(-0.5f, 0.5f, 0.5f);
pVector[14] = new
Vector3(-0.5f, 0.5f, -0.5f);
pVector[15] = new
Vector3(-0.5f, -0.5f, -0.5f);
pVector[16] = new
Vector3(-0.5f, -0.5f, 0.5f);
pVector[17] = new Vector3(-0.5f, 0.5f, 0.5f);
//right
pVector[18] = new
Vector3(0.5f, -0.5f, -0.5f);
pVector[19] = new
Vector3(0.5f, 0.5f, -0.5f);
pVector[20] = new
Vector3(0.5f, 0.5f, 0.5f);
pVector[21] = new Vector3(0.5f, -0.5f, -0.5f);
pVector[22] = new
Vector3(0.5f, 0.5f, 0.5f);
pVector[23] = new
Vector3(0.5f,- 0.5f, 0.5f);
//up
pVector[24] = new
Vector3(0.5f,-0.5f, 0.5f);
pVector[25] = new
Vector3(-0.5f, -0.5f, 0.5f);
pVector[26] = new
Vector3(-0.5f, -0.5f, -0.5f);
pVector[27] = new
Vector3(0.5f, -0.5f, 0.5f);
pVector[28] = new
Vector3(-0.5f, -0.5f, -0.5f);
pVector[29] = new
Vector3(0.5f, -0.5f, -0.5f);
/
/down
pVector[30] = new
Vector3(-0.5f, 0.5f, -0.5f);
pVector[31] = new
Vector3(-0.5f, 0.5f, 0.5f);
pVector[32] = new
Vector3(0.5f, 0.5f, 0.5f);
pVector[33] = new
Vector3(-0.5f, 0.5f, -0.5f);
扫描电子显微镜原理
pVector[34] = new
Vector3(0.5f, 0.5f, 0.5f);
网络公司名字
pVector[35] = new
Vector3(0.5f, 0.5f, -0.5f);
for (int nIndex = 0; nIndex
< pTriangles.Length; ++nIndex)
{
pTriangles[nIndex] = nIndex;
}
pMesh.Clear();
pMesh.vertices = pVector;//⽹格顶点iangles = pTriangles;//三⾓形pMesh.RecalculateBounds();
}
创建⼀个空物体
把MakeCube脚本挂在空物体上,运⾏即可。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。