I’m trying to update _Fill
property of my shader using Material.SetFloat
property. It works just fine, however it’s not updating in play-mode but only after stopping.
Using setMaterialDirty()
on Image.material
didn’t work.
public class OrbFillUpdater : MonoBehaviour
{
public IntegerReference Variable;
public IntegerReference Max;
private Material material;
private void Start()
{
material = GetComponent<Image>().material;
}
private void Update()
{
float value = Mathf.Clamp01(Mathf.InverseLerp(0, Max.Value, Variable.Value));
material.SetFloat("_Fill", value);
}
}
And here is _Fill
property.
_Fill("Fill Amount", Range(0, 1)) = 1
float _Fill;
fixed4 frag(v2f IN) : SV_Target {
// ... Code
if (IN.texcoord.y >= _Fill)
{
if (IN.texcoord.y + (noise.r - 0.7) * _NoiseStrength >= _Fill)
{
color.a = 0;
layer1.a = 0;
layer2.a = 0;
layer3.a = 0;
}
}
}