Fading texture to black is not working correctly

I’m trying to change a material’s texture to black over time. Based on the camera’s changing “y” value.
I’m trying to convert the RGB to HSV so I can slide the value from 255 down to 0 and “fade it out” to black.
But my update function is just…not doing what I expect it to. No results. The material just sits there regardless of the camera’s y value.

public class SkyScript : MonoBehaviour {

GameObject sky;
Color color;
float value = 255;
float h, s = 0;

// Use this for initialization
void Start () {
    sky = GameObject.Find("Sky");
}

// Update is called once per frame
void Update () {
    value = 255- (int)Camera.main.transform.position.y;
    color = sky.GetComponent<Renderer>().material.color;
    Color.RGBToHSV(color, out h, out s, out value);
    sky.GetComponent<Renderer>().material.SetColor("_MainTex", color);
}

}

Its not doing anything because at line 14 color is set to the sky’s current color and at line 16 you set the color of the sky to the exact same thing. Also, you need to convert HSVToRGB not the other way around. Finally you don’t want to get a component in the update function; this should be done in start. You need something like this:

using UnityEngine;
using System.Collections;

public class SkyScript : MonoBehaviour {
	
	public GameObject sky;
	public Color color;
	public float value = 255;
	public float h, s = 0;
	private Renderer rend;

	// Use this for initialization
	void Start () 
	{
		sky = GameObject.Find("Sky");
		rend = sky.GetComponent<Renderer> ();
	}

	// Update is called once per frame
	void Update () {
		value = 255- (int)Camera.main.transform.position.y;
		color = Color.HSVToRGB(h, s, (value/256));
		rend.material.color = color;
	}
}