Dear community,
Description:
In my current project, I’ve got a 2D game in which enemies are rendered using the sprite renderer and a custom shader that glows (representing shields). Once an enemy is killed, I change the material to one that lets me dissolve the enemy graphically before destroying the GameObject. The dissolve amount is a vector1 within the shader.
Error:
I change the material with the following code, the dissolveMaterial being a [SerializeField] Material I manually set to the DissolveMaterial in the editor:
public void Dissolve ()
{
gameObject.GetComponent<SpriteRenderer>().material = dissolveMaterial;
dissolve = true;
}
In the Update function, I then try to change the value of the dissolvePower. I have set the property name in the shade to “_DissolvePower” and it is shown like that when I select the shader in the editor.
private void Update ()
{
//check if the shields need to lowered or raised
RegulateShields();
if (dissolve)
{
gameObject.GetComponent<SpriteRenderer>().material.SetFloat ("_DissolvePower", Time.deltaTime);
}
if (gameObject.GetComponent<SpriteRenderer>().material.GetFloat ("_DissolvePower") >0.99f)
{
Destroy(gameObject);
}
}
However, when I run the code, Unity tells me there is no property by the name “_DissolvePower” in the shader… I really don’t understand what’s happening.
Edit: When I manually change the DissolvePower slider at runtime, the shader works correctly. It appears to me that, for some reason, Unity cannot find the correcly named and called property. Any idea how this could be alleviated?
Thanks a lot!