Acessing Shader Properties in a object that has two materials

So I wrote a shader with a particular float value that I’m trying to access Via a script. Im able to use the setFloat method with no problems with objects with only one material to work with. The thing is I’m experimenting my shader on Trees that came free in the Asset store. The thing is they working using 2 materials. And when I use renderer.material.setFloat it only works for one material in my case the trunk and not the leaves what I want to know is if there is a way to differentiate between materials when using renderer.material.setFloat

Use the renderer.materials array instead of renderer.material:

// set a float in the second material:
renderer.materials[1].SetFloat(...);