r/UnityHelp • u/makesnoZenZ • Aug 22 '23
Hello I need some help. I wrote this very simple Script but it wont work in game. When my Player reached level 3 his Material changes to the same Material as the Border thats blocking him from going further but it wont work. I assigned everything and doublechecked but I dont know what I did wrong.
0
Upvotes
2
u/nulldiver Aug 22 '23
So, what you’re likely experiencing is that the equality check fails because you’re dealing with instances of materials - and those instances aren’t the same object. You could try testing the renderer’s sharedmaterial, but it could depend on how/if you’ve modified materials.
This is definitely not how I would approach the problem though - inferring mechanics by testing materials. You’re better off setting a bool, an int/enum… even a string and testing that. Be explicit about what you’re doing in your code. Materials are for rendering. Things like sampling materials to turn off colliders have a way of coming back to haunt you.