Reputation: 915
I am working on 2D platform game. I have a sprite with a material and a shader I found here.
The shader have a value property that effect the dissolve effect of the sprite, but if I have the same GameObject multi times in my scene (as a prefab or instantiated through code), changing the dissolve value on one material affects all GameObjects with the same material (I tried changing material name, clone the material and all kind of stuff), I think I understated now that it his happening because I use the same sprite (image)
What can I do to avoid that kind of behavior?
float dissolvePower = dissoleMaterial.GetFloat(dissolveProperty);
float minus = -0.1f;
while (dissolvePower > 0)
{
//print(dissolvePower);
dissolvePower += minus;
dissoleMaterial.SetFloat(dissolveProperty, dissolvePower);
yield return new WaitForSeconds(0.07f);
}
print("Exit DeathDissolve()");
Destroy(gameObject);
Upvotes: 1
Views: 1863
Reputation: 2148
You are using the same material for each of your GameObjects.
Therefore, if you change a property (like the dissolve value) of the material, whether you do this in the Inspector for the GameObject or on the material itself, you will change the value for each GameObject that uses that material.
To avoid this, you need another material. You could duplicate the material, call it something different, and apply that material to a GameObject you want to be different.
Upvotes: 2