change the color of a car

Hello, newbie here.

I’m working with GUI. What i need is to change the color of a car by pressing buttons.

What i know:
-i can draw buttons (yeeee!)
What i don’t know:
-Make those buttons to find that specified material to change (the object has several materials in it).
-Assign color codes in the script.
-Where to put the script

I’m workin’ with some scripts from this forum, but i am still confused.

You could implement this by having several variables for the colour materials in your script and then assigning them appropriately when a button is pressed:-

var redMat: Material;
var greenMat: Material;
var blueMat: Material;
   ...

var car: Transform;

function OnGUI() {
    if (GUI.Button(redButtonRect, "Red")) {
        car.renderer.material = redMat;
    } else if (GUI.Button(greenButtonRect, "Green")) {
        car.renderer.material = greenMat;
    } else if (GUI.Button(greenButtonRect, "Blue")) {
        car.renderer.material = blueMat;
    } ...
}

thank you. I’ll try as soon as possible. Just a question:

“var redMat: Material;” redMat is the name of the material assigned to the object? If that material is called, say, “marsSurface” then i have to write:

var marsSurface: Material;?

thank you in advance

No, redMat is the name of the variable. You can assign a value to a variable in Unity by dragging an object to it in the inspector. Check out this manual page for further details.