Game Development Reference
In-Depth Information
//If the character has no velocity or very close to 0 show idle
animation
if(controller.velocity.sqrMagnitude < 0.1) {
animation[idleAnimation.name].speed = idleAnimationSpeed;
animation.CrossFade(idleAnimation.name, 0.1);
} else { //Checking if the character walks or runs
if (b_isRun) {
animation[runAnimation.name].speed = runAnimationSpeed;
animation.CrossFade(runAnimation.name, 0.1);
} else {
animation[walkAnimation.name].speed = walkAnimationSpeed;
animation.CrossFade(walkAnimation.name, 0.1);
}
}
}
}
//Update rotation of the character
if (v3_moveDirection != Vector3.zero) {
transform.rotation = Quaternion.LookRotation(v3_
moveDirection);
}
}
We just added the script to check what the animaion clip should play when the
character is in each acion. In the irst secion, we are checking if we are jumping. If we
are, we play also,
Jump and not jump
. If we are falling down, we play the
Fall and not
fall
. Then, if we are moving by walking, we play
Walk Animation
. If we are running, we
play
Run Animation
. If we are not doing anything, we play
Idle Animation
.
3. Finally, we go back to Unity and add the animaion clip to our character by clicking
on the
Heroine_animate
object in the
Hierarchy
View
to bring up its
Inspector
view, under the
Character Control
component in the
Inspector
view, and set
the following:
Idle Animation
:
idle
Walk Animation
:
walk
Run Animation
:
run
Jump Animation
:
jump
Fall Animation
:
fall