Gradients in 2D
How does one work with gradients in 2d? Say I want to have the alpha value transition from 1 or 255 (opaque) to 0 (completely transparent)? Or a color from red to white, etc...
I can't find any code examples, the docs show how to create a gradient with alphaKeys and colorKeys but no examples on how to use the gradient at all.
I found a tutorial on unity learn for pbr 3d shaders and gradients but it looks like it's not what I am looking for.
Could anyone offer some resources or explain how to apply a gradient on a sprite in 2D? I had figured it would be some extension of the color class but it does not appear to be so.
I am looking to create a vertical gradient where the top values are different than the bottom, similar to what you did with the rainbow, but with only two steps and vertical rather than horizontal. One specific use case that I am trying to achieve is having the lower half of a sprite have an alpha of zero while the top half has an alpha of 100%. Say for example, making someone look like they are standing in grass or in water by having their lower body have an alpha of 0.
Something like this (abstracted):
OnTriggerStay2D(Collider2D col)
{
ApplyGradientOrShader();
}
OnTriggerExit2D(Collider2D col)
{
RegularSprite(); // Color.white?
}
Here is what is would look like: