[Solved]The position of objects in space.

I am familiar Unity recently and am trying to create a game in the classic isometric view. And then the question arose as to realize the position of the character relative to objects (trees, walls, houses) that when it is in front of and behind the object. Can someone tell me the solution of this problem.

I’m trying to like this:

public class position : MonoBehaviour {
    public GameObject player;
    public GameObject[] trees;
    // Use this for initialization
    void Start () {
                player = GameObject.FindWithTag ("Player");
                trees = GameObject.FindGameObjectsWithTag ("Tree");
        }
    // Update is called once per frame
    void Update () {
        foreach (GameObject tree in trees) {
                        if (player.transform.position.y > tree.transform.position.y) {
                                player.renderer.sortingOrder = -1;
                        } else {
                                player.renderer.sortingOrder = 1;
                        }
                }           
    }
}

The does not work.
Please, help me.

You’re changing player’s sortingOrder every iteration thus overwriting last assignment each time your code iterates. What is it exactly you want to achieve with this?

What about this?

 if (player.transform.position.y > tree.transform.position.y) {
                                tree.renderer.sortingOrder = -1;
                        } else {
                                tree.renderer.sortingOrder = 1;
                        }
                }

Solved:

renderer.sortingOrder = (int)(transform.position.y * -10);