首页 > 代码库 > 更换模型的材质(点击鼠标左右键)

更换模型的材质(点击鼠标左右键)

using UnityEngine;using System.Collections;public class ChangeMatericals : MonoBehaviour {    public Material IniMaterical;// 替换前材质(原材质)    public Material ChangeMaterical;//替换后的材质(半透明材质)    private MeshRenderer mr;    int index;
void Start() { mr = GetComponent<MeshRenderer>(); mr.sharedMaterial = IniMaterical; } void Update() { if (Input.GetMouseButton(0)) { index = 0; Change(); } if(Input.GetMouseButton(1)) { index = 1; Change(); } } public void Change() { Debug.Log("更换!"); if (index==0) { mr.sharedMaterial = null; mr.sharedMaterial = ChangeMaterical; } if (index==1) { mr.sharedMaterial = null; mr.sharedMaterial = IniMaterical; } }}

 

更换模型的材质(点击鼠标左右键)