How do I trigger an animation using a button?

I want to know what script I have to use so that I can press a button(in this case, “Fire2”, and then an animation will play. I have an empty object(named “M4A1”) to act as a folder and inside I have “Main Body”(the chamber, middle and stock of the M4A1) which has the animation. I want the “M4A1” to have the script and the “Main Body” to have the animation. Also, I am Coding in C# :slight_smile:

Well I’m not a C# scripter but I can give you a script that plays the animation when Fire2 is pressed in Java.

function Update(){
   animation.Play("animation file");

Attach it to what you want to be played - in that case, the body.

thanks a lot! I just wanna know, do i put the file type(in this case, .anim) after the animation file name?

I tried it…it didnt work…it also wasnt an error because unity didnt say it had an error