Tilting the game object on the slopes


I’m making a 2d platformer in which I have slopes. My player should recognize the slopes and tilt accordingly. Is there any effective solution for recognizing the slopes? I have an idea to attach a small empty game object and test it against the land to determine whether he is on slope or not. Is it expensive to do this method? I would love to hear some of your solutions for the problem.

You need to fire a ray at the ground and get the surface normal from the hit info. Then you can use the normal direction to set your rotation.