Runtime Equivelent of EditorGUIUtility.HSVToRGB()

Apperently after about a month of work on this game I have, I hit build and it says that I can’t use EditorGUIUtility.HSVToRGB. So now, a couple of scripts in my game don’t work. In the first script, HueShift, I use HSVToRGB() to shift the hue to many color. Pretty simple except now that I cant use HSVToRGB() I need a similar set of code that does the same thing. And in the second one, CoinCreate, I use HSVToRGB() to pick a random (Nice looking) color. Again, all I’m looking for is something that works exactly like HSVToRGB(). Thats it. Thanks!

HueShift:

#pragma strict
var h : float = 0.0;
function Start () {

}

function Update () {

	gameObject.renderer.material.color = EditorGUIUtility.HSVToRGB(h, 1, 1);
	if(h < 1){
		h = h + 0.001;
	} else {
		h = 0;
	}

}

CoinCreater (Look at lines 29-33):

#pragma strict
var xpos : float;
var spawnpoint : Vector3;
var coin : GameObject;
var rotation : Quaternion;
rotation.eulerAngles = new Vector3(0, 0, 0);
var newCoin : GameObject;
var rate : float = 3.0;
var fasterRate : float = 0.0;
var scriptEnabled : boolean = true;

function Start () {
Invoke("CreateCoin", rate);
}

function Update () {

}

function setRate(newRate : float){
	rate = newRate;
}

function CreateCoin(){
	fasterRate = 0.05;
	xpos = Random.Range(-50.0,50.0);
	spawnpoint = new Vector3(xpos, 80, 0);
    
    var h : float = Random.Range(0.0,1.0);
	if(scriptEnabled){
		newCoin = Instantiate(coin, spawnpoint, rotation);
		newCoin.renderer.material.color = EditorGUIUtility.HSVToRGB(h, 1, 1);
	}
	if(rate > 0.4){
		rate = rate - fasterRate;
	}
	if(scriptEnabled){
		Invoke("CreateCoin", rate);
	}
}

function Unpause(){
	yield WaitForSeconds(rate);
	CreateCoin();
}

Based on a JS code (converters - Javascript convert HSB/HSV color to RGB accurately - Stack Overflow), I created this function (Unity Script) :

function HSVToRGB(h : float, s : float, v : float) {
	var r : float;
	var g : float;
	var b : float;
	var i : float;
	var f : float;
	var p : float;
	var q : float;
	var t : float; 
    i = Mathf.Floor(h * 6);
    f = h * 6 - i;
    p = v * (1 - s);
    q = v * (1 - f * s);
    t = v * (1 - (1 - f) * s);
    switch (i % 6) {
        case 0: r = v; g = t; b = p; break;
        case 1: r = q; g = v; b = p; break;
        case 2: r = p; g = v; b = t; break;
        case 3: r = p; g = q; b = v; break;
        case 4: r = t; g = p; b = v; break;
        case 5: r = v; g = p; b = q; break;
    }
    return Color(r,g,b); 
}

Thanks for posting this. Very useful. Here is the C# version:

    public Color HSVToRGB(float h, float s, float v)
    {
        h = h % 1;
        s = s % 1;
        v = v % 1;

        float r = 0;
        float g = 0;
        float b = 0;
        float f, p, q, t;
        int i;
        i = (int) Mathf.Floor(h * 6);
        f = h * 6 - i;
        p = v * (1 - s);
        q = v * (1 - f * s);
        t = v * (1 - (1 - f) * s);
        switch (i % 6)
        {
            case 0: r = v; g = t; b = p; break;
            case 1: r = q; g = v; b = p; break;
            case 2: r = p; g = v; b = t; break;
            case 3: r = p; g = q; b = v; break;
            case 4: r = t; g = p; b = v; break;
            case 5: r = v; g = p; b = q; break;
        }
        return new Color(r, g, b);
    }

Color.HSVToRGB