(2D)How to make my character jump properly??

I’m making a simple 2D game.I am trying to make my character jump properly. At the moment when i press and hold down spacebar the character continuously flys upwards.

#pragma strict

 var moveLeft : KeyCode;
 var moveRight : KeyCode;
 var Jump : KeyCode;	
 	
 var speed : float = 4;
 var JumpHeight : float = 10;

function Update () 
{
	if (Input.GetKey(moveLeft))
	{
		rigidbody2D.velocity.x = speed *-1;
	}
	else if (Input.GetKey(moveRight))
	{
		rigidbody2D.velocity.x = speed;
	}
	else
	{
		rigidbody2D.velocity.y = 0;
	}
	
	if (Input.GetKey(Jump))
	{
		rigidbody2D.velocity.y = JumpHeight;
	}
	else if (Input.GetKey(Jump))
	{
		rigidbody2D.velocity.y = speed;
	}
	

	
	
}

This is because you are using GetKey() which will be true in every frame that the key is held down. Thus you will add speed over and over again.

Use http://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html which will only fire once per key press.

In general, google and the docs are your friend. When something doesn’t work the way you expected it to, check the docs, your expectations are probably wrong.