|
Java Code - Player Jump
[Back]
Code:
//You put these on the top of the script, these are the start of it.
var jump :float = 0; //Check if the player can jump
var jumpspeed : float = 15; //Check how high the player can jump
var jumptimer :float = 0; //Make the player can jump again using this timer
//Put this next code in (Function Update() like show
//what this code do is make it show when the var Jump is = to 1 it keep making the Jumptimer go up
//when it 50 it will set Jump back to 0 and then set it self back to 0, when jump is 0 the player can jump again
function Update () {
if (jump == 1) {
jumptimer = jumptimer +1;
if (jumptimer >= 50) {
jumptimer = 0;
jump = 0;
}
}
}
//The next code make it show if you hit the W key and if the var Jump is 0 it will make the player jump then it will make //the Jump var to 1 so the player can't jump again.
//2D
if (Input.GetKeyDown ("w"))
{
if (jump == 0) {
rigidbody2D.velocity.y = jumpspeed;
jump = 1;
}
}
//3D
if (Input.GetKeyDown ("space"))
{
if (jump == 0) {
rigidbody.velocity.y = jumpspeed;
jump = 1;
}
}
var jump :float = 0; //Check if the player can jump
var jumpspeed : float = 15; //Check how high the player can jump
var jumptimer :float = 0; //Make the player can jump again using this timer
//Put this next code in (Function Update() like show
//what this code do is make it show when the var Jump is = to 1 it keep making the Jumptimer go up
//when it 50 it will set Jump back to 0 and then set it self back to 0, when jump is 0 the player can jump again
function Update () {
if (jump == 1) {
jumptimer = jumptimer +1;
if (jumptimer >= 50) {
jumptimer = 0;
jump = 0;
}
}
}
//The next code make it show if you hit the W key and if the var Jump is 0 it will make the player jump then it will make //the Jump var to 1 so the player can't jump again.
//2D
if (Input.GetKeyDown ("w"))
{
if (jump == 0) {
rigidbody2D.velocity.y = jumpspeed;
jump = 1;
}
}
//3D
if (Input.GetKeyDown ("space"))
{
if (jump == 0) {
rigidbody.velocity.y = jumpspeed;
jump = 1;
}
}