How to toggle the sprite layer in the game by script?

Good morning I would like to know if you have how to change the layer of the sprite by code for example has two paths to follow one down the ladder and one to pass straight through it has how to change the layer or is there another way to do this? help me please

GetComponent().sortingOrder = 1;
// etc.