How to update the orientation of the object according to change in gravity direction?

i have a tiny problem.i successfully changed the direction of gravity for the game,but am unable to change the orientation of the player based on the new direction of gravity.hope someone can help me.Here’s the script.

using UnityEngine;
using System.Collections;

public class gravity : MonoBehaviour {

// Use this for initialization

void Start () {
	Physics2D.gravity=new Vector3(0,-9.81f,0) ;

}

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

	if (Input.GetKey ("o")) {
		Physics2D.gravity=new Vector3(0,9.81f,0);

		Debug.Log ("roof");
			}
	else if(Input.GetKey(";"))
	{
		Physics2D.gravity=new Vector3(9.81f,0,0);

		Debug.Log ("right");
	}
	else if(Input.GetKey("k"))
	{
		Physics2D.gravity=new Vector3(-9.81f,0,0);
	
		Debug.Log ("left");
	}
	else if(Input.GetKey("l"))
	{
		Physics2D.gravity=new Vector3(0,-9.81f,0) ;

		Debug.Log ("floor");
	}

}

}

It can be done this way:

 var g = -Physics2D.gravity;
 var angle = Mathf.Atan2(g.y, g.x) * Mathf.Rad2Deg;
 transform.rotation = Quaternion.AngleAxis(angle+90.0f,Vector3.forward);

Note this the use of the ‘+90.0f’ assumes the natural orientation of your object is Vector3.up when the rotation is (0,0,0).