I have code like that:
Renderer render = gameObject.GetComponent<Renderer>();
Material material = render.material;
if (material.HasProperty("_MainTexOpacity"))
{
float var = material.GetFloat("_MainTexOpacity");
}
It Works in some materials but when i have some material that have the property “_MainTexOpacity” but dont have any Float, appears this error:
Material doesn’t have a float or range property ‘_MainTexOpacity’
UnityEngine.Material:GetFloat(String)
My question is, have some way to see if the material have float?
I wanna do somethink like that:
Renderer render = gameObject.GetComponent<Renderer>();
Material material = render.material;
if (material.HasProperty("_MainTexOpacity"))
{
if (material have GetFloat)
{
float var = material.GetFloat("_MainTexOpacity");
}
}