Question by
oen432 · Jul 02, 2019 at 10:18 PM ·
c#scripting problemshadermaterial
Material.SetFloat not updating.
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.
My script
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;
}
}
}
Comment
Tried using set$$anonymous$$aterialDirty()
on Image.material
but it didn't work.
Your answer
Follow this Question
Related Questions
How can i make a tiled/striped texture on a sphere ? (see example below) 0 Answers
Specular Material Not Updating, but Standard is ok? 1 Answer
Change alpha on material with custom shader 0 Answers
Raw Image changing texture in inspector but not in game. 1 Answer
Unexpected symbol error in shader script 0 Answers