Rotate Cube Depending On Where The Cursor Is

Hello, I am making a top down perspective game I want the player (in this case a cube) to rotate around like a compass North, West,East,South but also having the ability to be facing NorthWest and SouthEast and everywhere in between. Can anyone throw me in the right direction with a script tutorial?

If this were a 3d game, I’d say transform.LookAt() but that doesn’t exactly work correctly for 2D games. Instead I use this method:

public static void LookAt2D(ref GameObject obj, Transform target)
    float angle = 0;

    Vector3 relative = obj.transform.InverseTransformPoint(target.position);
    angle = Mathf.Atan2(relative.x, relative.y) * Mathf.Rad2Deg;
    obj.transform.Rotate(0, 0, -angle);

This rotates the object on the Z plane to look at the target.