Change material color with a three slider

Hi everyone,

I’m a beginner in programming and I’m trying to change the color of my material by using a UI with 3 sliders.
I manage to change the color with the slider but it’s only affect the script and not the material (I create a visualization of the color in the script, that I can see in the inspector of my mesh).

I’m very closed, I just need to match my color with the one of material and it will be good and I can’t found how to do it.

Here the code:

public Color altColor;
public Renderer rend;
public Material colors;
void slider()
{
    altColor.r = 0.5f;
    altColor.g = 0.5f;
    altColor.b = 1.0f;
}
void Start ()
{
    slider();
    Renderer rend = GetComponent<Renderer>();
    rend.material.color = altColor;
    //Material rend = GetComponent<Material>();
    //rend.material.colorRed = altColor;
}

public void colorRed (float newRed)
{
    altColor.r = newRed;
}
public void colorGreen(float newGreen)
{
    altColor.g = newGreen;
}
public void colorBlue(float newBlue)
{
    altColor.b = newBlue;
}
// Update is called once per frame
void Update () {

}

Thanks @alucardj for the corrective comment…here is my updated answer. (I removed the slider function and call because I’m assuming that’s there only for testing?)

using UnityEngine;
using System.Collections;

public class ColorChanger : MonoBehaviour {
	public Color altColor;
	private Renderer rend;

	void Start ()
	{
		// Make sure you only get the rend component here
		// because when you get the color, you only store the
		// values of the color, not access to the color of 
		// the material.
		//
		// Also, 'rend' accesses the declared, private renderer
		// so this CAN'T be:
		//
		// Renderer rend = GetComponent<Renderer>();
		//
		// because that would store a new 'rend' that would not be 
		// accessible outside of this function.
		rend = GetComponent<Renderer>();
	}

	// set r, g, and b floats with slider
	public void colorRed (float newRed)
	{
		altColor.r = newRed;
		// Here we get the color of the 'gotten' Renderer
		rend.material.color = altColor;
	}
	public void colorGreen(float newGreen)
	{
		altColor.g = newGreen;
		rend.material.color = altColor;
	}
	public void colorBlue(float newBlue)
	{
		altColor.b = newBlue;
		rend.material.color = altColor;
	}
}