How do you change layer weight with code?

I want to change the animation layer weight with code, what I am doing is that when the player enters a BoxCollider2D the player’s animation swaps with new animations, The problem is that I don’t know how to do that.

(For context I am making a top down 2D game not a 3D game.)

For anyone wondering, the answer to the literal question of “how do you change layer weight with code” is: Animator.SetLayerWeight(int layerIndex, float weight)