How to rotate/tilt an object to match angle of slope?

The title says it all. Here is my code(In C#)

float spinSpeed = 2000f;
float moveSpeed;
float gravity = 40f;
float moveLimit;
RaycastHit hit;
Vector3 moveDirection = Vector3.zero;
CharacterController controller;

// Use this for initialization
void Start ()
{
    controller = GetComponent<CharacterController>();
    animation.wrapMode = WrapMode.Loop;
    animation["Take 001"].speed = spinSpeed;
    animation.CrossFade("Take 001");
    moveLimit = controller.slopeLimit - 0.1f;
}

// Update is called once per frame
void Update()
{
    if (Input.GetAxis("Horizontal") > 0.1)
        moveSpeed = 15f;
    else if (Input.GetAxis("Horizontal") < -0.1)
        moveSpeed = 15f;
    else if (Input.GetAxis("Vertical") > 0.1)
        moveSpeed = 15f;
    else if (Input.GetAxis("Vertical") < -0.1)
        moveSpeed = 15f;
    else
        moveSpeed = 0f;

    if (Vector3.Angle(hit.normal, Vector3.up) > moveLimit)
        transform.rotation =
            Quaternion.FromToRotation(Vector3.up, hit.normal) * Quaternion.LookRotation(moveDirection);

    moveDirection = new Vector3(Input.GetAxis("Vertical"), 0, Input.GetAxis("Horizontal"));
    moveDirection = transform.TransformDirection(moveDirection);

    moveDirection.y -= gravity * Time.deltaTime;
    controller.Move(moveDirection * (Time.deltaTime * moveSpeed));
}

I don't really get what you are talking about. Actually I never worked with raycast in my game.

The above script does not work as desire, could you post more information how to use the code?