- Home /
Player Animation HELP REQUIRED PLEASE
I have two different animations both linked to one GameObject (MainPlayer). i made a script for it to play the running animation when "w" is held, when its let go play standing. This is the code i have but it doesnt play the standing :( If Anybody could help that would be awesome.
function Update () {
if (Input.GetKeyDown ("w"))
{
//gameObject.animation.Stop(Stand);
gameObject.animation.CrossFade("Walking");
}
if (Input.GetKeyUp ("w"))
{
//gameObject.animation.Stop(Walk);
gameObject.animation.CrossFade("Standing");
}
}
Answer by venkspower · Apr 12, 2012 at 06:40 AM
Instead of using animation.CrossFade(), use animation.Play().
Answer by fafase · Apr 12, 2012 at 06:42 AM
I would think you main problem is the input yu are using. GetKeyDown only returns true on the frame it goes down meaning only once and then back to 0. I think what you want is GetKey which returns true as long as you are pressing the key. If you release the else takes place and the animation is standing.
function Update () {
if (Input.GetKey ("w")) {
animation.CrossFade("Walking",0.2f);
}
else{
animation.CrossFade("Standing",0.2f);
}
}
Not really sure though which of GetKey or GetButton is right...The documentation does not really explain any differences..
mmm thanks, what is happening is that when i let go of the "w" it stops playing the Walking but doesnt start playing the Standing. Thanks for the help... I'll get back to you on the Status :)
Could be the length of your animation that is too short see this http://answers.unity3d.com/questions/165123/animation-crossfade-wont-play-but-animation-play-d.html Try removing the 0.2f (though they should work) or use animation.Play() and see how it goes.
mmm are you sure the animation is attached/written properly/simply doing anything? (we never know...)
Since the first goes fine, swap the animations and see if your guy is "standing animating" when you press.
If not, that means it comes from the animation itself and you would have solved 1/2 of the pb.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to make a animation rotation js.script? 2 Answers
animation.Play isn't working 1 Answer
Why cant i get my animation to play? 0 Answers
Climb animation is glitchy and isnt working properly 0 Answers