- Home /
my attack animation is not working
I have downloaded a demo of a project so then I can look at it and understand it but for some reason my attack animation does not want to work when I click my mouse but when I activate the trigger manually while the game is running it works. I don't know if its the animator method I'm using or the input method. and I've spent more than a day on this with no luck so I really need some help. I also designed a way of doing the first attack animation first and if in a certain amount of time the attack button is pressed again it will do the second animation. alt text
Answer by thetoby2004 · Feb 16, 2021 at 12:46 PM
yes the script doas not know which animator you want to Trigger .. if the animator component is on the same GameObject as the script is, you can just add:
> animator = GetComponent<Animator>();
in the Start() Function
Answer by xxmariofer · Feb 16, 2021 at 10:40 AM
You have multiple errors in the console that mostlikely are the cause of the issue, fix them before trying to make it work, it looks like a nullreference exception, make the Animator public instead of private, and drag and drop the reference from the inspector
Answer by DevManuel · Feb 16, 2021 at 03:57 PM
In your code you have a private variable animator, but that variable is never set to an instance. That's what the error message is saying. So you could do this: void Start(){ animator = this.gameObject.GetComponent(); }
Then your animation should work.
,In your script you have a private variable animator, but it's not set to an instance of an object. Thats what the error message says. So you could add this to your code:
void Start(){
animator = this.gameObject.GetComponent<Animator>();
}
then your animation should work.