I have 3 jump animations; jumping up, jumping down, and the loop in between. I want to play them in an order, using logic.
When the player presses space, I should play the "jumping up" animation, followed by the "jump loop" while player is in air, and the "jumping down" animation just before touching the ground. If the player falls from a height, I should play the "jump loop" animation while in air, followed by the "jumping down" animation just before touching the ground.
This is what I have so far, to provide the animation:
void Update ()
{
if (!animator)
{
return;
}
float vSpeed = Input.GetAxis ("Vertical");
animator.SetFloat ("VSpeed", vSpeed);
if (Input.GetButtonDown ("Jump"))
{
animator.SetBool ("Jumping", true);
Invoke ("StopJumping", 0.1f);
}
if (!charController.isGrounded)
{
animator.SetBool ("Grounded", false);
RaycastHit hit;
Ray downRay = new Ray (transform.position, Vector3.down);
if (Physics.Raycast (downRay, out hit))
{
animator.SetFloat ("Distfromground", hit.distance);
}
}
}
void StopJumping()
{
animator.SetBool ("Jumping", false);
}
Am I doing anything wrong, or is there a better way to do this? As it is, it is not giving me the desired effects.