PLaying an animation on click

Im trying to get it so when you press Mouse0 (primary mouse button) it will play an animation called "punch"

Im kind of a "noob" at java but here is what I got:

@script RequireComponent(CharacterController)

    public var punchAnimation : AnimationClip;

if(!punchAnimation) {

    _animation = null;

    Debug.Log("No animations, turning them off");

}

if(_animation) {

        if(Input.GetKey (KeyCode.Mouse0)) {

            animation.Play("punchAnimation"); 

        }

}

Please help!!

2 Answers

2

code

if(Input.GetMouseButton(0)) { animation.Play("punch"); }

place it on the object which has the animation.

The commad get button down shold fix it if not let me know

so if you keep clicking it works fine ?

yea have a look at the new one i just updated :) that should be good

wait a minute are you telling me if you let go the animation stops ? that's not right it should play it first then play after its finished playing if you want me to have a look at at send it to me at my google or hotmail account : Hotmail: gto_oni-eyes@hotmail.com google mail Hummad.Nazir@googlemail.com

ok yep thats fine as soon as you are done send me the link

If you want the animation to finish you could try checking your mecanim settings for that particular animation and check ‘has exit time’. If that’s not then issue then it should be in this segment you posted:

`if(!punchAnimation) {

_animation = null;

Debug.Log(“No animations, turning them off”);`

If I’m reading it correctly it’s saying if the condition is not met (mouse has gone up) then animation = null (stopping the animation perhaps?). Hopefully this helps you track the source of the issue so it can be resolved. Cheers.