After reading the API info here: https://docs.unity3d.com/ScriptReference/TrailRenderer-colorGradient.html

I am wondering if I can "tune in" my trail renderer in the normal unity interface, print those complicated code parameters, then use that code in my script to change color on triggers, etc.

To clarify, how do I get the information here presented in code: [Trail Renderer Inspector View]

I guess I am approaching this from a CSS background. Is there a Unity colorgradient version of this website: https://www.colorzilla.com/gradient-editor/

Can I make the script print the characteristics of the trail renderer (for the purpose of replicating it elsewhere in my code)?

1

Much appreciate the help!

1 Answers

0
derHugo On

I'm still not 100% sure if I understood the question but I'll give it a shot.

As I understand you want to have a component on every trigger object where you can define different gradient settings for each.

And I assume by Unity interface you mean the Inspector.

So something like e.g.

public class GradientSetter : MonoBehaviour
{
    public GradientColorKey[] colorKeys;
    public GradientAlphaKey[] alphaKeys;  
}

Put this on the trigger object(s) and adjust the settings via the Inspector. At beginning they should be empty arrays so to add elements just enter the wanted element count in the size property of both arrays.

And wherever you have the Collision implemented on your TrailRenderer object

void OnTriggerEnter(Collider other)
{
    var gradientSetter = other.GetComponent<GradientSetter>();
    if(!gradientSetter) return;

    gradient.SetKeys(gradientSetter.colorKeys, gradientSetter.alphaKeys);

    ...
}

I'm assuming GradientColorKey and GradientAlphaKey are Serializable. If you implement this but they don't show up in the Inspector let me know, then you'll have to make a wrapper class for them. (I can't test it right now)


Note: Typed on smartphone so no warranty but I hope the idea gets clear