Help with adding jump function to player.

I added or tried to add a jump function similar to how I added the move function. I also tried it the same way I added crouch/attack function. It doesn’t do anything though he just sits still. Sometimes I can get it to work, but if I tap the button he barely moves up and the animation doesn’t continue. I tried GetButtonUp but that doesn’t work either.

Lines with asterisk symbols is what I tried to do to add jumping.

heres the code with jump function in it:

 public float speed = 1.0f;
*****public float jumpspeed = 1.0f;******

 
 
    private Transform thisTransform;
    private Sprite sprite;
    private bool flipped;
 
    // Use this for initialization
    void Awake () {
       thisTransform = transform;
       sprite = (Sprite)GetComponent(typeof(Sprite));
 
    }
 
    // Update is called once per frame
    void Update () {
       Vector3 moveVector = new Vector3(0,0,0);
       bool moving = false;
************bool jumping = false;*************
	
	*********if(Input.GetKey(KeyCode.Space)){
			 moveVector.y += 2.0f;
			jumping = false;
		}*************
		
 
 
 
    if(Input.GetKey(KeyCode.A)){
         moveVector.x -= 1.0f;
         moving = true;
 
    }
 
       if(Input.GetKey(KeyCode.D)){
         moveVector.x += 1.0f;
         moving = true;
 
 
       }
 
 
       if(Input.GetKey(KeyCode.Mouse0)){
         Attack();
       } else {
         if(!IsAttacking()) {
          if(moving) {
              Move(moveVector);
          } else {
              Stand();
         }
       }
       
       if(Input.GetKey(KeyCode.S)){
         Crouch();
       } else {
         if(!IsCrouching()) {
					
			}
				 if(moving) {
              Move(moveVector);
          } 
				else {
         Stand();
    }
    }
       }
    }

 
 
 
 
 
    private void Stand() {
       sprite.Stop();
    }
 
 
    private void Move(Vector3 moveVector) {
       FlipSprite(moveVector.x);
       moveVector *= speed * Time.deltaTime;
       thisTransform.position = thisTransform.position + moveVector;
       sprite.Play("walk");
 
 
 
 
    }
 
    private void FlipSprite(float x) {
       if(x == 0.0f) return;
 
       float xDir = Mathf.Sign(x);
       if(!flipped && xDir < 0.0f) {
         flipped = true;
         sprite.SetFlippedState(true, false);
       } else if(flipped&& xDir > 0.0f) {
         flipped = false;
             sprite.SetFlippedState(false, false);
       }
    }
 
    private void Attack() {
       if(IsAttacking()) return;
 
       sprite.Play("Sword");
    }
 
    private bool IsAttacking() {
       if(sprite.IsAnimationPlaying("Sword")){ return false;}
       return false;
 
 
}
 
    private void Crouch() {
       if(IsCrouching()) return;
 
       sprite.Play("crouch");
    }
 
    private bool IsCrouching() {
       if(sprite.IsAnimationPlaying("crouch")) {return false;}
       return false;
 }
	
  ************private void Jump(Vector3 moveVector) {
       FlipSprite(moveVector.x);
       moveVector *= jumpspeed * Time.deltaTime;
       thisTransform.position = thisTransform.position + moveVector;
       sprite.Play("jump");****************
 
 
 
 
    }
 
 
 
 
 
}

I don’t see you calling Jump() anywhere. Somewhere tween 45 - 65 you are probably falling through to Stand(), Google ‘fence the wolf’ and use some print/debugs to see where your code is failing.

I fixed it myself heres the new script if any one wants to see it:

using UnityEngine;
using System.Collections;
using SpriteFactory;

public class player : MonoBehaviour {

public float speed = 1.0f;
public float jumpSpeed = 10.0f;
public float gravity = 20.0f;
public bool grounded = true;


private Transform thisTransform;
private Sprite sprite;
private bool flipped;

// Use this for initialization
void Awake () {
   thisTransform = transform;
   sprite = (Sprite)GetComponent(typeof(Sprite));

}

// Update is called once per frame
void Update () {
   Vector3 moveVector = new Vector3(0,0,0);
   bool moving = false;
	
	moveVector.y -= gravity * Time.deltaTime;
	
	if(Input.GetKeyDown(KeyCode.Space)){
		 Jump();
		
		
		
	}

	



if(Input.GetKey(KeyCode.A)){
     moveVector.x -= 1.0f;
     moving = true;

}

   if(Input.GetKey(KeyCode.D)){
     moveVector.x += 1.0f;
     moving = true;


   }


   if(Input.GetKey(KeyCode.Mouse0)){
     Attack();
   } else {
     if(!IsAttacking()) {
      if(moving) {
          Move(moveVector);
      } else {
          Stand();
     }
   }
   
   if(Input.GetKey(KeyCode.S)){
     Crouch();
   } else {
     if(!IsCrouching()) {
				
		}
			 if(moving) {
          Move(moveVector);
      } 
			else {
     Stand();
}
}
   }
}






private void Stand() {
   sprite.Stop();
}


private void Move(Vector3 moveVector) {
   FlipSprite(moveVector.x);
   moveVector *= speed * Time.deltaTime;
   thisTransform.position = thisTransform.position + moveVector;
   sprite.Play("walk");




}

private void FlipSprite(float x) {
   if(x == 0.0f) return;

   float xDir = Mathf.Sign(x);
   if(!flipped && xDir < 0.0f) {
     flipped = true;
     sprite.SetFlippedState(true, false);
   } else if(flipped&& xDir > 0.0f) {
     flipped = false;
         sprite.SetFlippedState(false, false);
   }
}

private void Attack() {
   if(IsAttacking()) return;

   sprite.Play("Sword");
}

private bool IsAttacking() {
   if(sprite.IsAnimationPlaying("Sword")){ return false;}
   return false;

}

private void Crouch() {
   if(IsCrouching()) return;

   sprite.Play("crouch");
}

private bool IsCrouching() {
   if(sprite.IsAnimationPlaying("crouch")) {return false;}
   return false;

}
void Jump(){
if(grounded == true)
{
rigidbody.AddForce(Vector3.up * jumpSpeed);
grounded = false;
}
}

void OnCollisionEnter(Collision col){
	if(col.gameObject.tag == "floor"){
		grounded = true;
		sprite.Play("jump");
	}
		
	
	}

}