unity绘制cube的方式
(2019-09-05 10:38:23)
标签:
unity |
分类: 我的学习生活 |
https://docs.unity3d.com/ScriptReference/PrimitiveType.Cube.html
using UnityEngine; using System.Collections;
// Creates a cube primitive
public class ExampleClass : MonoBehaviour { void Start() { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); } }
https://blog.csdn.net/nanggong/article/details/54314699
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class Test3D : MonoBehaviour
{
public Material mat;
// Use this for initialization
void Start()
{
DrawCube();
}
#region 画正方体
void DrawCube()
{
gameObject.GetComponent().material = mat;
Mesh mesh = GetComponent().mesh;
mesh.Clear();
//设置顶点
mesh.vertices = new Vector3[]
{ 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),
};
//设置三角形顶点顺序,顺时针设置
mesh.triangles = new int[]
{
0, 2, 1,
0,3,2,
3,4,2,
4,5,2,
4,7,5,
7,6,5,
7,0,1,
6,7,1,
4,3,0,
4,0,7,
2,5,6,
2,6,1
};
}
#endregion
}
前一篇:windowsapi获取所有窗口

加载中…