r/UnityHelp • • 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.

Post image
0 Upvotes

2 comments sorted by

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.

1

u/makesnoZenZ Aug 23 '23

Hey nulldiver. Thank you very much for your respond. I tried doing it with a bool and I got everything to work just right. For the material change I just give the Player the same Material as the border like I wanted it but only when the bool is true, so the Material change dont really effects anything but the player can still see the different Material and knows that the border is now unlocked, even if it has nothing to do with the Color.

Thank you again :)