- Home /
how do i use two animations on the same object??
Hey :),, Okay basicly i cant figure this out i have been trying for weeks now I have a Walk animation, and a shoot animation i use "W" to activate the walk animation and Left mouse click to shoot how can i make it so that when i hold "W" and The "left mouse button" it walks and shoots at the same time if anybody could help that would be amazing,, This is the code i use now ?
function Update ()
{
if(Input.GetKey("w"))
animation.CrossFade("Walk_Boom");
else if(Input.GetKey("mouse 0"))
animation.CrossFade("Shoot_Boom");
else
animation.CrossFade("Idle_Boom");
} The simple code i no Thanks :P..
Answer by Owen-Reynolds · Dec 20, 2011 at 12:11 AM
Lots of possible ways. Most obvious: in Start, set shoot to a higher layer, but upper body only. Have it as a PlayOnce (in the Inspector, for Assets.)
public Transform LowerSpineBone; // drag this in
Start() {
animation["shoot_Boom"].layer=5; // anything past 0
// Assuming lower spine is start of upper-body bone chain, legs not on it:
// shoot should now be upper body only
animation["shoot_Boom"].AddMixingTransform(LowerSpineBone);
// can also use (Transform.Find("bones/lowerSpine")
}
Playing shoot_boom should now have upper body play shoot, leave lower body walking/idling. When shoot is done, upperbody should resume walking.
The animation docs explain this all, but take a few reads before you get the idea.
Your answer
![](https://koobas.hobune.stream/wayback/20220613062222im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Animation stoping!! 1 Answer
Help with an animation script. 1 Answer
Where is the problem? 0 Answers