- Home /
Animation Not Playing
so basically i have a sword and a First Person Controller , and i have an animation which swings the sword, and i have it so when you left click, he should swing the sword, but for some reason when i press play, the character won't activate the animation.
the script goes like this:
function update ()
{
if (Input.GetKeyDown("Fire1"))
{
animation.Play("Sword attack");
}
}
So could someone help me on figuring out what the problem might be?
Are you sure you have the animation "Sword attack" in your animation component? Are you getting any errors?
$$anonymous$$ake sure that update is Update. If you're animation is not attached to the same object that your script is attached to then change it to GameObject.Find("the object it's attached to").animation.Play("Sword attack");
I Got it to work by using getaxis, but then when the animation plays, my character screen rotates 90 degrees, then comes back, HELP!
and no syclamoth, im not getting any errors, besides when it is on get $$anonymous$$ey down and i play and press ctrl or left click it says "input key:"Fire1" is unknown"
Answer by donutkeith · Jul 09, 2013 at 04:35 AM
Some thing you probably want is to also add to you conditions is !animation.IsPlaying("Sword attack") so you want:
if(Input.GetKeyDown("Fire1") && !animation.IsPlaying("Sword attack"))
{
animation.Play("Sword attack");
}
Reasoning update runs over and over so your only gonna play the first few milliseconds of the animation before you start playing it again because play always starts at the beginning.
Also make sure that your animation variable is not null meaning you should have something like: private var animation : Animation
Side note: I usually use _animation instead of just animation so i make sure not to be confused.
or you could use: GetComponent()
Also as was mentioned above use Update not update. Hope this helps.
Your answer
Follow this Question
Related Questions
Animation & Script Help 2 Answers
Unity3D AI using animations 1 Answer
How would I go about making an animation affected by this script? 1 Answer
my animation script does not work 0 Answers
Simple Attack Script Problem 2 Answers