I'm going to reply myself just in case is useful for somebody in the future. After some investigations, I found out that is not a good idea to compare materials between different objects, as the ID of the material might be different that the name you see in the debug mode.
So basically I had to take another approach and get the name of the gameObjects instead and storage them in string variables. That way I could confirm that both strings were the same, therefore, I managed to make work my script.