Sorting Order Not Working Correctly

I am trying to change the order of a sorting layer in unity for a 2D game but the below script isn’t working for me:

using UnityEngine;
using System.Collections;

public class LevelManager : MonoBehaviour {

public GameObject player;
public SpriteRenderer deadGuy;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

    if (player.transform.position.y < deadGuy.transform.position.y)
    {
        deadGuy.sortingOrder = 0;
    } else
    {
        deadGuy.sortingOrder = 2;
    }

}

}

any idea why this wouldn’t be working correctly? The objects have been linked in unity before running the game in the inspector window.

The below code worked for me:

using UnityEngine;
using System.Collections;

public class LevelManager : MonoBehaviour {

public GameObject player;
public GameObject deadGuy;

// Use this for initialization
void Start () {

    deadGuy.GetComponent<SpriteRenderer>().sortingOrder = 2;

}

// Update is called once per frame
void Update () {

    if (player.transform.localPosition.y < deadGuy.transform.localPosition.y)
    {
        deadGuy.GetComponent<SpriteRenderer>().sortingOrder = 0;

    } else
    {
        deadGuy.GetComponent<SpriteRenderer>().sortingOrder = 2;
    }

  }
}

You just need to make sure that both objects are on the same layer and that the ‘player’ object in my case, is set to sorting order 1