error with instance of TerrainData?

I have this code:

var terrain : Terrain;
function FixedUpdate()
    if (Input.GetButton ("Crouch"))
        if (transform.position.y > terrain.terrainData.GetHeight(transform.position.x, transform.position.y))
            transform.position.y =transform.position.y - transform.position.y/50;

And I'm getting this error:

"NullReferenceException: Object reference not set to an instance of an object Commander.FixedUpdate ()"

the error comes up when I press crouch and points to the 2nd if statement line.

can anyone help me resolve this error?

Drag your terrain into the `terrain` slot in the inspector. `terrain` is just a var name, and isn't auto-hooked up to anything, even though is looks like it is.

BUT, you probably want this instead (and can lose the terrain var):