Ira*_*ris 4 mesh unity-game-engine
我在 Unity 中构建了一个自定义金字塔,如下所示:
Mesh mesh = GetComponent<MeshFilter>().mesh;
mesh.Clear();
Vector3[] vertices = {
new Vector3(0.0f, 0.5f, 0.0f),
new Vector3(0.5f, 0.0f, 0.5f),
new Vector3(-0.5f, 0.0f, 0.5f),
new Vector3(-0.5f, 0.0f, -0.5f),
new Vector3(0.5f, 0.0f, -0.5f),
};
int[] triangles = {
1, 2, 3,
1, 3, 4,
1, 0, 2,
2, 0, 3,
3, 0, 4,
4, 0, 1
};
mesh.vertices = vertices;
mesh.triangles = triangles;
Run Code Online (Sandbox Code Playgroud)
我正在尝试为我的金字塔着色,正如在这样的统一文档中所说:
Color[] colors = new Color[vertices.Length];
for (int i = 0; i < vertices.Length; i++)
colors[i] = Color.Lerp(Color.red, Color.green, vertices[i].y);
// assign the array of colors to the Mesh.
mesh.colors = colors;
Run Code Online (Sandbox Code Playgroud)
但这不会改变任何事情..
我的对象上没有材料,只有这个脚本。有任何想法吗?
请注意mesh.colors中的注释
//(请注意,大多数内置着色器不显示顶点颜色。使用可以显示的着色器(例如粒子着色器)来查看顶点颜色)
因此,为了在MeshRenderer组件中看到这些颜色,请添加使用此类顶点或粒子着色器的材质。
所以
在Project视图(资产)中做right click→ Create→Material
给那个材料起个名字
对于Shader从下拉菜单中找到并选择例如Particles→ Standard Unlit(或者如果您想接收闪电Standard Surface)
最后将此材质用于您的对象,方法是将其拖入MeshRenderer→material或简单地将其拖到Scene视图中的相应对象上(如果该对象尚无网格,则后者可能不起作用)
结果:
| 归档时间: |
|
| 查看次数: |
3660 次 |
| 最近记录: |