Nordaj123 is right
Try this?
MonoBehavior{
private float JumpHeight = 2; // try to increase if no effect.
bool grounded = false;
void Update(){
if (grounded == false && GetComponent().velocity.y == 0){
grounded = true;
}
if (grounded && Input.GetButtonDown ("Jump")){
GetComponent().AddForce(Vector2.up*JumpHeight);
//JumpHeight in this case is a force. Vector2.up* Jumpheight
// means for the player to launch up by the force specified.
{
}
void OnCollisionEnter (Collision col){
if (col.gameObject.tag == "FloorTagHere") {
//replace FloorTagHere with whatever
//function: when the player contacts a jumpable surface
grounded = true;
}
}
void OnCollisionExit (Collision col){
if (col.gameObject.tag == "FloorTagHere"){
//function: when the player leaves the jumpable surface aka. jumps
grounded = false;
}
}
↧