0
\$\begingroup\$

So I made a simple White Flash -> Dissolve effect with shader graph 2D, it's my 1st time using shaders. I'm controlling the effect using a float inside the shader, with:

Material.SetFloat("FLOAT_NAME", 0-1f); 

And I'm wandering how can a control only a single instance of my Shader without affecting all my enemies.

Example: I have 20 enemies, all from the same prefab with the same material. I want to be able to make 1 enemy dissolve whenever I shoot at him.

\$\endgroup\$
1
  • \$\begingroup\$ Have you looked into MaterialPropertyBlocks? \$\endgroup\$
    – DMGregory
    Commented Jun 9, 2020 at 10:16

1 Answer 1

0
\$\begingroup\$

Not sure how to mark as solved, but my problem was using the wrong reference, I referenced the Material directly, instead of the spriteRenderer material.

\$\endgroup\$
1
  • \$\begingroup\$ You'll be able to mark this as solved by clicking on the green checkmark on your question after a short delay. In the meantime, you could improve this question by showing the difference in code/inspector setup between what you were doing before, and what you did to fix it, so future users can learn from your example. Keep in mind that using the renderer.material getter creates a copy of the material, so be sure to clean up unneeded copies when you're done with them to reduce garbage and keep batching working for you. \$\endgroup\$
    – DMGregory
    Commented Jun 9, 2020 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .