How to invert material sequence in object ?

Hey guys.

I have a script, that take the firt material in object and make it red when mouse enter it.
I have 3 objects in scene, two of them the material that i want to change be red, and the other has another material firt…I only want to know how to invert it, put the second material first them another

If your GameObject is ‘object,’ here is C# code:

Material tempMaterial = object.renderer.materials[0];
object.renderer.materials[0] = object.renderer.materials[1];
object.renderer.materials[1] = tempMaterial;