How to check if variable defined in script is present in shader?

Hi,

I have two different shaders for water, first one with MainTexture and BumpMap property, another with MainTexture, BumpMap and DistortionMap property (basically two/three different textures for each shader to create water scene).

I am trying to alter the speed of each of these texture properties through script. The problem is I am trying the script to check if the selected shader has DistortionMap property (which is only present in the second shader) or not and display the option to alter the DistortionMap Speed (in script) accordingly.

I’ll be glad if anyone can help here…

Thanks in advance.

material.HasProperty(“_Color”);

Usually does the trick. Just replace the string “_Color” with your distortion map variable name.

// Example of checking shader properties.
void SetDistortionSpeedExample(Material _water, float _amount)
{
    if(_water != null && _water.HasProperty("_DistortionMap"))
    {
        if (_water.HasProperty("_DistortionSpeed"))
        {
             _water.SetFloat("_DistortionSpeed", _amount);
        }
    }
}