how to select the correct material in an object that counts several ones ?

Hi there,

Some basic stuff I can’t deal with.

I have a scene kinda virtual showcase with design objects and need to change there colors / materials with Gui sliders.
Despite the limitation of lerp.material (wich unfortunately does not allow to change texture map or shader type) I managed to write a little script that works :

var style : GUIStyle;
var hSliderValue : float;
var material1 : Material;
var material2 : Material;

function OnGUI () {
	GUI.skin.horizontalSlider = style;
	hSliderValue = GUI.HorizontalSlider (Rect (25, 25, 300, 30), hSliderValue, 0.0, 1.0);

}


function Update () {
	var lerp = hSliderValue;
	renderer.material.Lerp (material1, material2, lerp);
}

The issue there is that this script only applies on the FIRST material of the Mesh Renderer list.
How could it select another entry (example “element 2 material”) so that :
1/ it’s the correct part of the model that changes
2/ in some cases I need to have several sliders corresponding to several materials of the same objects (example metal / wood / plastic parts of it).

Any help appreciated.

bump

Use renderer.materials instead of renderer.material.

–Eric

hum…
thank you very much for reply.

But a bit more would be possible ?
I just replaced it as you suggested and the only thing I get is a console error message :

‘Lerp’ is not a member of ‘UnityEngine.Material[ ]’.

What am I missing ? Guess some way to “select” correct materials as variables but how to get them ?

Unity - Scripting API: Renderer.materials It’s an array, you modify the entry or entries you want to use.

–Eric

OK thanx Eric, I’m gonna look at it.

Here I am, now this was too simple.
Shame I did not find it myself.

thx again.