how to change the render sequence in 2D game ?

for example, the player stands in front of a tree , the player will cover the tree , when the player is behind the tree,the tree will cover the player,how to achieve that ? need i change the render sequence in the code ?

Better than using Z transform is to use the Sorting Layer option on the SpriteRenderer component. There is additional option called Order In Layer - this number controls the draw order of sprites belonging to the same Sorting Layer. Order In Layer is effectively a subdivision of Sorting Layer.

Both can be accessed through code if you want to change them at runtime.

If you are just dealing with 2D sprites, changing the Z value in the transform position should change the render order.

player z = 1 tree z = 0 = player in front of tree
player z = 0 tree z = 1 = player behind tree

You can change this z value based on the y values. If the Y value of the player is higher that the y value of the tree, change the players z value to a lower value than the trees z value.

Hope this helps,
-Larry