Home Game Development unity – How can I make the hue of a cloth change over time?

unity – How can I make the hue of a cloth change over time?

0
unity – How can I make the hue of a cloth change over time?

[ad_1]

You would first wish to get the fabric hooked up to the gameObject.

// If you may have a reference to the GameObject referred to as "myGameObject":
Renderer renderer = myGameObject.GetComponent<Renderer>();
// If the article you need is the one this script is hooked up to:
Renderer renderer = GetComponent<Renderer>();
 
// This creates a particular materials only for this one object. If you modify this materials it's going to solely have an effect on this object:
Material mat = renderer.materials;
 
// This will get the shared materials utilized by this renderer. If there are different renderers that use the identical materials, altering this materials may also have an effect on them.
Material mat = renderer.sharedMaterial;

Note: Use .sharedMaterial if you wish to change the fabric’s shade on all sport objects with this materials. Note 2: If you may have a number of scripts all accessing the identical .sharedMaterial, what each does will stack (that means when you enhance hue, it’s going to enhance quicker).

Then, later within the script you’ll be able to enhance hue, by doing:

public foat velocity;

float h, s, v;
void Update()
{
    Color shade = mat.shade;

    Color.RGBToHSV(shade, out h, out s, out v);
    h += Time.deltaTime * velocity;
    h = h % 1f; //Max worth it may be. For non-hdr, it's 1
//I do not know what it's for hdr, perhaps attempt 255f
    mat.shade = Color.HSVToRGb(h, s, v, false);
//set the bool to whether it is hdr

In the road that goes h = h % 1f, set 1f to 1f it’s not hdr. (I have no idea what hdr max worth is for HSV values, because the scripting api was not very clear) if i needed to guess although, it might be 1f or 255f.

In the ultimate line of code, set the bool to if it must be hdr.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here