How to rotate around object axis

Hi I am trying to rotate a box around an axis that is one of the bottom edges of the cube of cuboid by 90 degrees depending on whichever arrow key i press. I want to know how to write a script for this.

edit(copied from answer-comment)

there are four edges of a cube that are touching the ground at any instant when the cube is stationary. imagine a crate lying on the floor. now take any edge that touches the ground. I will select the edge based on the four arrow keys that i can press. so i want to rotate 90 degrees around that edge so that the crate rotates in one direction and stays on the floor

Transform.RotateAround could be used for that but i guess you want to slowly rotate so you can see the rotation and not just the end-result of the rotation. In this case it’s easier to use an empty gameobject, place it on the axis you want and parent your cube to the empty gameobject. Now you can rotate the empty GO around it’s center. After the rotation unparent the cube. That’s the easiest way :wink:

edit
Something like that should do what you want but if you want the cube to “roll” on uneven ground you have to do it with physics and use a rigidbody and try something similar with forces. Unfortunately there’s no AddTorqueAtPoint…

var rotator : Transform;
var speed = 1.0;
var halfCubeSize = 0.5;
private var rotating = false;

function RotateCube(refPoint : Vector3, rotationAxis : Vector3)
{
    rotator.localRotation = Quaternion.identity;
	rotator.position = transform.position -Vector3.up*halfCubeSize + refPoint;
	transform.parent = rotator;
	var angle : float = 0;
	while(angle < 90.0)
	{
	    angle += Time.deltaTime*90.0*speed;
		rotator.rotation = Quaternion.AngleAxis(Mathf.Min(angle,90.0),rotationAxis);
	    yield;
	}
    transform.parent = null;
	rotating = false;
}


function Start()
{
    rotator = (new GameObject("Rotator")).transform;
}

function Update ()
{
    if (!rotating)
    {
        if (Input.GetKey(KeyCode.D))
        {
            rotating = true;
            RotateCube(Vector3.right*halfCubeSize,-Vector3.forward);
        }
        else if (Input.GetKey(KeyCode.A))
        {
            rotating = true;
            RotateCube(-Vector3.right*halfCubeSize,Vector3.forward);
        }
        else if (Input.GetKey(KeyCode.W))
        {
            rotating = true;
            RotateCube(Vector3.forward*halfCubeSize,Vector3.right);
        }
        else if (Input.GetKey(KeyCode.S))
        {
            rotating = true;
            RotateCube(-Vector3.forward*halfCubeSize,-Vector3.right);
        }
    }
}

I’ve created a quick-and-dirty webbuild of this test :wink:
WASD to move the cube

@grady the bottom edge of the cube

there are four edges of a cube that are touching the ground at any instant when the cube is stationary. imagine a crate lying on the floor. now take any edge that touches the ground. I will select the edge based on the four arrow keys that i can press. so i want to rotate 90 degrees around that edge so that the crate rotates in one direction and stays on the floor

Easiest way I found is in this answer:
http://answers.unity3d.com/answers/649789/view.html