Moving and rolling a cube

Hi, i have already read some questions like this and I have also found not simple scripts that work but I can’t understand it. I have to move the player, a cube with a rigidbody (on the x axis) and everytime it does a step it will rotates of 90 degrees, how can I do it (is better via script or animation/animator, and how)? Actually my movement script is this (the cube rotates “physically”, but not in the “correct way” with the freeze rotation on the z axis turned off)

 using UnityEngine;
 using System.Collections;
 public class mov : MonoBehaviour
     public float velocità;
     private Rigidbody rb;
     public bool IsGrounded;
     public int jumpP;
     void Awake(){
         IsGrounded = true;
         rb = GetComponent<Rigidbody> ();
     void OnCollisionEnter(Collision other){    
             IsGrounded = true;
     void FixedUpdate()
         float movevert = Input.GetAxis ("Vertical");
         float movehoriz = Input.GetAxis ("Horizontal");
         Vector3 movement = new Vector3 (movehoriz, 0.0f, movevert);
             rb.velocity = rb.velocity + movement * velocità/2;
         if (IsGrounded == true) {
             if (Input.GetButton ("salto")) {
                 rb.velocity = new Vector2 (0f, jumpP);
                 IsGrounded = false;

Here’s a short Youtube video that covers exactly how to roll a cube on its edges: How to Move a Cube by Rolling it | Unity Tutorial - YouTube

rolling cube