Either loop through a copy of the materials array, and assign the copy back to the renderer, or use SetGlobalFloat, if you need the same thing to happen to all materials.
Also, GetComponent is also a method of Component, so you don’t need gameObject. in there. But that point is kind of moot in this case, due to the .renderer property.