Question by
bivayushiy · Sep 20, 2021 at 10:04 PM ·
scripting problemtexturematerialmaterials
What right way to SetTextureOffset of material which has dynamic count owners?
I want to SetTextureOffset of one sharedMaterial, which has dynamic count of owners instead of using cycle to set offset of material instances. Now I have 2 solutions: 1 - Change offset of every material instance in a cycle:
private void Update()
{
if (isHighlighted)
{
foreach (var material in materials)
{
material.SetTextureOffset(shaderVariable, offset);
}
}
}
2 - Change offset of one sharedMaterial in alone MonoBehaviour object on scene every frame even if count of objects is zero:
private void Update()
{
SharedMaterial.SetTextureOffset(shaderVariable, offset);
}
But I feel there is a good decision. Thank you for help.
Comment