(For demonstration purposes we assume you applied the shader material on a Image component but this works for anything)
For some reason you cannot simply do myImage.material.SetXXX(shaderVarKey, myValue)
.
To edit a variable you have to
-
have a ref to your
Graphic
component (for example anImage
) -
implement
IMaterialModifier
on your mono script -
implement
GetModifiedMaterial
public virtual Material GetModifiedMaterial(Material baseMaterial)
{
// protected Material _material;
_material = new Material(baseMaterial);
_material.SetFloat(progressHandle, currentProgress);
return _material;
}
- Each time you edit your script value (which is used in the
SetXXX
function, herefloat currentProgress
) callSetMaterialDirty
on yourGraphic
component.