Hiya, I’m actually working on the same thing as you and I initially used colliders to check if I was on a ladder too, but I came across problems with the way I was doing things (for example, if you had a ladder object (tile) on top of another ladder object - when you exit the first, you’re setting gravity back on but you want to get onto the second one and need to still be climbing etc).
So Physics2D.OverlapCircle was more useful and accurate for me to check if I was touching a ladder or on ground. I’ve got two empty gameobjects on my Player object, one placed in the head area, and the other on the feet area (we’ll call them Head and Feet). You need to put the position of your feet or head, the radius of the circle this affects, and which layers it affects for the parameters for Physics2D.OverlapCircle, and it’ll return true if it hits that layer.
The checks I did were like this:
If Feet is touching the ground (any object with a ground layer), we’re in grounded mode. If Head and Feet touch ladder, we check if the player presses up. If they do, we set climbing mode to true and set the player’s rigidbody2D.gravityScale to 0 as well as change his animator settings for his animation etc (player can’t jump and other things in this mode either). In this mode, if the player keeps pressing up, his Feet will not touch the ground anymore since he’s climbing, which is fine, but when he presses down and his Feet does touch the ground again, we put the player in normal running mode (set gravity scale to 1, set climbing mode to false, animation to idle etc and he’s back on the ground again. A good thing is that the player can’t continually try to climb down and collide and judder with the ground.
For my game, when the player reaches the top of the ladder (when the Head check is not touching a ladder, I put an addForce to the character so he jumps up and off the ladder), but you can get him to be grounded and running again. You’ve got it so when the player exits the top of the ladder, gravity is set back on, so he’ll just slowly fall down until he hits the ground again. Oh, and don’t set all gravity to 0, that seems like more trouble that its worth ;)…
If there’s a ground tile on top of the ladder, I do collision checks here to switch the ground object from collider2D.isTrigger from true to false, depending on whether the we’re entering the collision with the Head, or if we’re exiting it with feet so that we can turn the ground tile/object so that we can jump through it or run on it again.
Ladders are a pain the butt, you need to do a whole lot of checks, but once you’ve conquered them, they’re awesome 