Changing a material with a mouse click

I'm a Unity noob so please bear with me!

I want to be able to click on an object and change its material. I would like to have the option of doing this 2 different ways:

1) Simply repeat clicking on the object will change the material to the next one. 2) Click on the object to display a GUI that I can pick what material I want.

Any ideas how I would approach this? Thanks.

I just got on here to find this same thing! But I got an answer:

You need to define an array for materials, place the materials in the array by selecting them in the GUI, and then use a function to change the rendering material. Here is my project that involves the object changing material when it's health hits 1:

var health: int; var materials : Material[];

function Update () { if ( health == 1 ) renderer.sharedMaterial = materials[0]; else renderer.sharedMaterial = materials[1];


All you have to do is a write a function that controls the array index via mouse click!

Well, here is simple script for GUI button...

var object : GameObject;
var texture : Texture;

function OnMouseDown(){
    object.renderer.material.mainTexture = texture;