Unity笔记:更换物体材质球
程序员文章站
2022-06-10 23:48:52
...
public Material m01,m02;//需要更换的材质球
void Update () {
if (Input.GetMouseButtonDown(0)) //点击鼠标左键时
{
gameObject.GetComponent<MeshRenderer>().materials[0].CopyPropertiesFromMaterial(m01);
}
else if (Input.GetMouseButtonDown(1))//点击鼠标右键时
{
gameObject.GetComponent<MeshRenderer>().materials[0].CopyPropertiesFromMaterial(m02);
}
}