How to make player go through an object or obstacle and but can't go back

So i am making a 2d game in which when a player jumps i want him to go through wall but then it stays there and does not fall back , i wanted to do it with multiple walls

You can try bool. When pass though make an object with collision, make the bool to false and on another side make is true…
I am also beginners, and I will also read other’s solution.