Make a cube bounce off four walls

Hi,

I finally got the cube moving within a confined area but after colliding with two walls in quick sucession it breaks through - as seen here at 21- seconds : http://screencast.com/t/NjczNzYxMWQt

I was told the best way to avoid this would be to start again and use physics but the problem is im not too sure where to start and I dont want to recreate that mistake.?

The code currently used is:

var speed : int = 20;

function Awake()
{
//print ("no collision as of yet");
}   

function Update () 
{

    transform.position += transform.forward * Time.deltaTime * speed;

}   

function OnTriggerEnter (hit : Collider)
{
    var rot = Quaternion.FromToRotation(Vector3.forward, hit.transform.up);
    transform.rotation = rot;
    transform.rotation.eulerAngles += Vector3(0, Random.Range(-90,90), 0);
}

It only seems to work with planes as the walls , if I try cubes or box collides the cube object seems to fly up instead of doing any bouncing? Thanks

The answer to your question would be pretty much identical to the one I wrote for another question recently, so I'll just link to it:

http://answers.unity3d.com/questions/13402/getting-maze-walls-using-3d-meshes-to-work/13418#13418

Also, if your cube has a rigidbody, you should be doing movements inside `FixedUpdate` instead of `Update`