- Home /
 
How do I get my melee animations to play?
I have a first person controller with a weapon attached to it. The weapon has 2 animations, an idle and an attack. How do I get the attack animation to play upon clicking the mouse? I tried attaching this script to the weapon:
 function Update () 
 {
 if(Input.GetButtonUp("Fire1"))
 {            animation.Play("tools_stone_axe_attack01.anim", PlayMode.StopAll); }}
 
               I have this java script attached to the game object that has the animations. I can't really code whatsoever, but I try to patch together code from different answers and tutorials I find. Apparently this code doesn't work. The Unity console says "The animation state tools_stone_axe_attack01.anim could not be played because it couldn't be found!" This confuses me. I know the animation is there. Did I format the name incorrectly?
I just want my attack animation to play on primary mouse button clicking and I want the animation to switch the the idle animation when it's done.
remove the playmode.stopall and see if that doesn't get you swinging
Answer by billyda59 · Jun 30, 2013 at 04:06 PM
I understand that Unity isn't finding the animation.
1 - The scripted game object DOES have the animations attached. The game object is selected in the screenshot and you can see the inspector on the right of the screen. The animation element shows 2 animations.
2 - I think the code doesn't like all the underscores I used in the animation name. I've tried removing the animation file extension in the code, but that didn't help. This is the only thing that I'm not sure about.
3 - You can see in the screenshot that the script IS attached to the game object.
Something maybe worth noting is that I've made these animations using unity, not blender.
or another option is using an Animation State $$anonymous$$achine.
it's a good way of blending two or more animations together.
Answer by ownerfate · Aug 31, 2013 at 11:19 AM
i have only got as far as playing the animation on Mouse click.
i can't figure out how to force it back to an Idle state.
but this is how i animated stuff for me.
SCRIPT:
   function Update(){
     
     if(Input.GetMouseButtonDown (0)){
     
         GameObject.Find("GavinBlade").animation.Play("ghostBladeAttack");
     }
 
 
               GameObject.Find(" name of the object that holds the animation clips ").animation.Play(" Name of the Animation itself ");
i hope this is somewhat helpful.
Your answer
 
             Follow this Question
Related Questions
how can you mount weapons when they do not appear until runtime? 1 Answer
I cant add scripts to my weapons,i can't add Scripts to my weapon 1 Answer
How to make shotgun unity 3d 0 Answers
Can I use Mecanim animation clips in Legacy? 1 Answer
How to play the animation completely on mouse click 1 Answer