Game Development Reference
In-Depth Information
_verticalSpeed = jumpSpeed;
_isJumping = true;
_inAirTime = 0.0f;
_inAirStartTime = Time.time;
}
}
}
C# user:
void Update () {
} else {
_verticalSpeed -= GRAVITY * Time.deltaTime;
_inAirTime = Time.time - _inAirStartTime;
}
if (!_isJumping && (_motionState ==
MOTION_STATE.GROUND)) {
_isRun = (Input.GetKey (KeyCode.LeftShift) ||
Input.GetKey (KeyCode.RightShift));
_moveSpeed = (_isRun) ? runSpeed : walkSpeed;
if (Input.GetButtonDown ("Jump")) {
_verticalSpeed = jumpSpeed;
_isJumping = true;
_inAirTime = 0.0f;
_inAirStartTime = Time.time;
}
}
}
8. The last section of code that we will add to the Update() function is to control
our character's movement and rotation, which is a very important part to create
our character when we press the button to control it. Let's add the following high-
lighted code in continuation with the last step:
// Unity JavaScript user:
function Update () {
Search WWH ::




Custom Search