Jump Script for a 2D game

I'm working to a 2D game, I have this script

private var jumping : boolean = false;  
var horSpeed : int = 0;

function Start ()

function Update () 

{transform.position.z -= Time.deltaTime * horSpeed;}

{transform.position.z += Time.deltaTime * horSpeed;}

if(Input.GetButtonDown("Jump") && jumping == false && rigidbody.velocity.y == 0

| rigidbody.velocity.z != 0)  
    {jumping = true;                                    
    rigidbody.velocity.y -= Physics.gravity.y + 2;                                      

else if(rigidbody.velocity.y < 0)
jumping = false;}


It works well but if I move on z and I hit a wall in a jump, the player remains stucked in the wall.

You really should be using a CharacterController for this, but one of the problems I see is that you're translating left and right. I don't see any point in using a rigidbody if you then move the character mostly through translation.

Especially for the left and right movement, I would instead use `addForce`, as that will cause the rigidbody to obey physics and slide down the wall (if the friction is low) rather than stick to it.