Version: 2017.1
public void Clear ();

描述

清除材质属性值。

Graphics.DrawMesh 复制传递的属性代码块,因此使用它的最高效方式是 创建一个代码块并将它重复用于所有 DrawMesh 调用。使用 Clear 可清除代码块的值, 使用 SetFloatSetVectorSetColorSetMatrix 可添加值。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Mesh aMesh; public Material aMaterial = new Material(Shader.Find("VertexLit")); void Update() { MaterialPropertyBlock materialProperty = new MaterialPropertyBlock(); materialProperty.Clear(); materialProperty.SetColor("_Color", Color.red); Graphics.DrawMesh(aMesh, new Vector3(5, 0, 0), Quaternion.identity, aMaterial, 0, null, 0, materialProperty); materialProperty.Clear(); materialProperty.SetColor("_Color", Color.green); Graphics.DrawMesh(aMesh, new Vector3(-5, 0, 0), Quaternion.identity, aMaterial, 0, null, 0, materialProperty); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961