jumping error!?

i am making a 2d platformer that involves jumping but when i put my code in it gives me this error: Unknown identifier moveDirection. but i know it should a known identifier because it's highlighted orange!

my script:

var jumpSpeed = 5.0;

if(Input.GetKeyDown("UpArrow"))

{

moveDirection.y = jumpSpeed;

}

p.s. please help!

It's unknown because you haven't defined it anywhere. You need to define variables before you can use them.

Try this.

var jumpSpeed = 5.0;
var moveDirection : Vector3;

if(Input.GetKeyDown("UpArrow"))
{
    moveDirection.y = jumpSpeed;
}

I believe you should be approaching this issue in a different way, I recommend you to use AddForce and study a little about the Rigidbody2d component in your Player, also check about ForceMode like Impulse.

 public float Speed;
 void FixedUpdate()
 {

     if (Input.GetKey(KeyCode.Space))
     {

         GetComponent<Rigidbody2D>().AddForce(Vector2.up* Speed);
     }
 }

var jumpSpeed = 5.0;
var moveDirection Vector2;
if(Input.GetKeyDown(“UpArrow”))

{

moveDirection.y = jumpSpeed;

} //this is javascript, so not good at javascript
// lower 1 is c#
//============
public float jumpSpeed;
public Rigidbody2D rb2d;
void Start() {
rb2d = GetComponent();
}

void Update()
{

  if (Input.GetKey("up"))
  {
     Vector2 movement = new Vector2(0, 5);
      if(movement != Vector2.zero) {
      rb2d.AddForce(movement * jumpSpeed);

}
}
}