I’m trying to get this function to only happen when player has landed. Also to reset when player has jumped.
#pragma strict
public var jumpForwardVel : float = 5f;
public var jumpUpVel : float = 20f;
//var Gravity : float = 10f;
var chargeLevel : float = 0;
//Don't change this in the inspector.
var chargeSpeed : float = 1;
//Default, the charge will go up 1 per second
var canJump = boolen(false);
//Is player grounded.
function Update () {
if (Input.GetKey(KeyCode.Space)) { //Is the user Clicking?
chargeLevel += Time.deltaTime * chargeSpeed; // Increase charge
}
if (chargeLevel > 2) {
this.gameObject.rigidbody.AddForce(Vector3(jumpUpVel, jumpForwardVel, 0) * chargeLevel, ForceMode.Impulse);
chargeLevel = 0;
}
if (Input.GetKeyUp(KeyCode.Space)) { // Did the player just stop clicking?
// do the actual jumping here-
// this takes the actual charge level into account-
this.gameObject.rigidbody.AddForce(Vector3(jumpUpVel, jumpForwardVel, 0) * chargeLevel, ForceMode.Impulse);
// now reset the charge level!
chargeLevel = 0;
}
if (canJump){
OnCollisionEnter : boolean = true;
}
}