Hi I am new to unity3d.
i am just trying to change the Material of wall at run time…
So i just import the model of house form Google Sketch up…
Which have different material in one object…As you can see in inspector view…
my problem is that when ever i click the next button “>>” it change the first material of the object…As shown in image, Red circle in inspector view is representing that the first material is changing and in game view there is next button under the red circle…
Some how if i get the ref of other elements then that will be great for me…
Code is given below…
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 () {
}//end of if 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();
}//end of OnGUI Funcation
}
