Basically the model in the scene has to be simply setup - each part that has a material(s) is tagged and when I click on it it should cycle through the available materials set in the inspector. It works with one so far but I have some issues with more than one; Now regardless where I click it changes only the first object in the list (walls)
var matArrayWalls : Material[];
var walls : GameObject;
var roof : GameObject;
var matArrayRoofs : Material[];
private var indexWalls : int;
private var indexRoofs : int;
function Update () {
if (Input.GetMouseButtonDown(0)){
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
indexWalls++;
indexWalls = indexWalls % matArrayWalls.Length;
indexRoofs++;
indexRoofs = indexRoofs % matArrayRoofs.Length;
if (Physics.Raycast(ray, hit)){
if(hit.collider.tag == "walls")
{
walls.renderer.material = matArrayWalls[indexWalls];
}
if(hit.collider.tag == "roof")
{
roof.renderer.material = matArrayRoofs[indexRoofs];
}
}
}
}
↧