how to lock rotation

i have been having problems with my 3rd person shooter script and it looking the direction that hte camera is looking, and i finally got the answers but it is not complete yet. this is my script that is attached to the player so it looks at a cube attached to the camera.

function Update()
     var cube : Transform;

now that it works i only want my character to look around, not up and down because the gun will do that. so how would i do that?

You can just get the Y axis out of the lookat? So

transform.LookAt(new Vector3(cube.position.x,transform.position.y,cube.position.z));

Or something like that.