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.
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.
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.