You would first want to get the material attached to the gameObject.
// If you have a reference to the GameObject called "myGameObject":
Renderer renderer = myGameObject.GetComponent<Renderer>();
// If the object you want is the one this script is attached to:
Renderer renderer = GetComponent<Renderer>();
// This creates a special material just for this one object. If you change this material it will only affect this object:
Material mat = renderer.material;
// This gets the shared material used by this renderer. If there are other renderers that use the same material, changing this material will also affect them.
Material mat = renderer.sharedMaterial;
Note: Use .sharedMaterial
if you want to change the material's color on all game objects with this material. Note 2: If you have multiple scripts all accessing the same .sharedMaterial, what each one does will stack (meaning if you increase hue, it will increase faster).
Then, later in the script you can increase hue, by doing:
public foat speed;
float h, s, v;
void Update()
{
Color color = mat.color;
Color.RGBToHSV(color, out h, out s, out v);
h += Time.deltaTime * speed;
h = h % 1f; //Max value it can be. For non-hdr, it is 1
//I don't know what it is for hdr, maybe try 255f
mat.color = Color.HSVToRGb(h, s, v, false);
//set the bool to if it is hdr
In the line that goes h = h % 1f
, set 1f to 1f it is not hdr. (I do not know what hdr max value is for HSV values, as the scripting api was not very clear) if i had to guess though, it would be 1f or 255f.
In the final line of code, set the bool to if it should be hdr.