Game Development Reference
In-Depth Information
Step 5. Play. The walk animation will play when the left arrow key is down,
and the jump animation will play when the space is pressed. The issue
now is that the animations only play once; for example, when the left
arrow key is pressed the walk animation plays and then stops. To fix this,
add the code in Listing 3.22 to the very top of the controls.js file.
Listing 3.22 Setting an Animation to Loop
function Start()
{
this.animation["walk"].wrapMode = WrapMode.Loop;
}
Step 6. Play. The walk animation will now loop. It will only stop when the
space bar is pressed for the jump animation.
Step 7. To make the model go into an idle mode when no key is pressed,
you need to add an idle animation. To do this, select the model in Project
and add an animation called idle with a start frame of 201 and an end
frame of 401. Click the Apply button.
Step 8. The idle animation won't be added automatically to the model in
the scene. Therefore, select the Lerpz object in the Hierarchy and locate
the Animation component in the Inspector. Change the number
of animations from 2 to 3. Set the third animation to idle .
Step 9. Edit controls.js to reflect the code in Listing 3.23 .
Listing 3.23 Adding an Idle Animation to Play after Other
Animations Are Finished
//REMOVE START FUNCTION
//function Start()
//{
//this.animation["walk"].wrapMode = WrapMode.Loop;
//}
function Update ()
{
if( Input.GetKey ("right"))
{
this.animation.Play("walk");
}
else if( Input.GetKey ("space"))
{
this.animation.Play("jump");
}
this.animation.CrossFadeQueued("idle", 0.5);
}
Search Nedrilad ::




Custom Search