Game Development Reference
In-Depth Information
at the same time or include an animation in which the character is
moving and shooting simultaneously. Instead of creating an entirely
new animation, you can blend the top of the shooting animation
with the bottom of the walking animation with code. Add the code in
Listing 3.27 to your script.
Listing 3.27 Creating a Blended Animation
private var speed = 0.03;
private var rotationSpeed = 0.5;
private var currentAnimation = "";
function Start()
{
...
this.animation["ShootStraight"].wrapMode = WrapMode.
Clamp;
//create a blended animation
this.animati on.AddClip(animation["ShootStraight"].
clip, "ShootUpperBody");
this.animati on["ShootUpperBody"].AddMixingTransform(
this.transform.Find("Reference/RightGun"));
this.animati on["ShootUpperBody"].AddMixingTransform(
this.transform.Find("Reference/Hips/Spine"));
this.animati on["ShootUpperBody"].wrapMode =
WrapMode.Clamp;
this.animation.Stop();
}
function Update ()
{
currentAnimation = "idle";
...
if(translation > 0)
{
this.animation.CrossFade("WalkForward");
currentAnimation = "walk";
}
...
if(Input.GetKeyDown("space"))
{
if(currentAnimation == "walk")
{
this.animation.CrossFade("ShootUpperBody");
}
else
{
Search Nedrilad ::




Custom Search