- Home /
Animation scripting problems
This is part of my animation script for my gun, I have altered it a bit to what I thought would make sense but it does not work. Before I changed the script When W or S is pressed it plays my walk animation but when A or D is pressed it still plays the idle animation, so I thought if I put horizontal instead of vertical it would work but instead I get a ton of errors. Can anyone help me out?
if(Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) // I added the i of if [Berenger]
animation.CrossFade("walk");
else
animation.CrossFade("idle");
if(Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
animation.CrossFade("walk");
else
animation.CrossFade("idle");
Answer by Berenger · May 21, 2012 at 03:48 PM
Horizontal < 0.1 is going to crossfade Idle, overriding the vertical input. Try that :
var v : float = Mathf.Abs(Input.GetAxis("Horizontal"));
var h : float = Mathf.Abs(Input.GetAxis("Vertical"));
if( h > 0.1 || v > 0.1 )
animation.CrossFade("walk");
else
animation.CrossFade("idle");
// OR
animation.CrossFade(( h > 0.1 || v > 0.1 ) ? "walk" : "idle" );
I get an error saying "GetAxis can only be called from the main thread" Whats going wrong?
Is this inside of Update or in a function called in Update ?
I had the variables outside Update it works now, thanks for your help.
Your answer
Follow this Question
Related Questions
Reacting to Mouse animation... 2 Answers
Loop animation on button hold 2 Answers
Error message, HELP!!! 1 Answer
Trying to simply play this animation... Help please. 1 Answer
A node in a childnode? 1 Answer