- Home /
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# :)
Answer by BigBlob · Apr 09, 2012 at 03:34 PM
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(){
if(Input.GetButtonDown("Fire2"));
animation.Play("animation file");
{
Attach it to what you want to be played - in that case, the body.
$$anonymous$$ake sure that if(Input.GetButtonDown("Fire2")); doesn't have the ; after it and that your second parentheses is the other way round (}).
I'm pretty sure this is just the same in C# but ins$$anonymous$$d of function Update () it's void Update () (because it has no return).
Answer by PDANY35 · Apr 10, 2012 at 03:39 PM
thanks a lot! I just wanna know, do i put the file type(in this case, .anim) after the animation file name?
Answer by PDANY35 · Apr 10, 2012 at 03:39 PM
I tried it.....it didnt work.....it also wasnt an error because unity didnt say it had an error
Your answer
Follow this Question
Related Questions
play only one door animation 1 Answer
Please help in triggering an animation through another object. 1 Answer
Button animation state stays Pressed or Highlighted after disabling GameObject 0 Answers
issue rendering animation on button click 1 Answer
How to play an animation on button press only in trigger stay? 1 Answer