0
我試圖在運行時更改牆壁的Material
。我從Google Sketchup導入房屋模型,它在一個對象中有不同的材質(這在檢查器中顯示)。每當我點擊下一個按鈕(>>
),它就會更改對象的第一個材質。我如何獲得對其他元素的引用?這是我到目前爲止有:Unity 3d - 渲染的材質選擇
public class Material_GUI : MonoBehaviour {
public Material[] mats;
public GameObject go;
private int index = 0;
// Use this for initialization
void Start() {
go.renderer.material= mats[index];
}
// Update is called once per frame
void Update() {
}
void OnGUI(){
GUILayout.BeginArea(new Rect(Screen.width/2-100,Screen.height-60,200,50));
GUI.Box (new Rect(10,10,190,40),"");
GUI.Label(new Rect(62,20,100,20),"Wall Testing"+(index +1));
if(GUI.Button (new Rect(15,15,30,30),"<<")){
index--;
if(index<0){
index = mats.Length - 1;
}
go.renderer.material = mats[index];
}
if(GUI.Button (new Rect(165,15,30,30),">>")){
index++;
if(index > mats.Length -1){
index = 0;
}
go.renderer.material = mats[index];
}
GUILayout.EndArea();
}
}