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 ()
So could someone help me on figuring out what the problem might be?
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"))
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.