Game Development Reference
In-Depth Information
rigidbody2D.velocity = newVelocity;
}
#endregion
#region If the player should jump
if(_isJump) {
_animator.SetTrigger("Jump");
audio.volume = 0.3f;
audio.PlayOneShot(jumpSound);
rigidbody2D.AddForce(new Vector2(0f,
jumpForce));
_isJump = false;
}
#endregion
#region If the player should fall
if (!_isGrounded) {
if ((rigidbody2D.velocity.y <= 0f) && !_isFall)
{
_animator.SetTrigger("Fall");
_isFall = true;
}
}
#endregion
#region If the player is grounded
if (_isGrounded) {
if (_isFall) {
_animator.SetTrigger("Ground");
_isFall = false;
} else {
AnimatorStateInfo animationStateInfo =
_animator.GetCurrentAnimatorStateInfo(0);
if ((rigidbody2D.velocity.y < 0f) &&
(animationStateInfo.IsName("Base Layer.Jump"))) {
_animator.SetTrigger("Fall");
_isFall = true;
}
}
}
#endregion
Search WWH ::




Custom Search