欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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);
    }
}