0
\$\begingroup\$

I'm working with Unity3D 5x using C#. I've attached collision detection to the character controller script that plays a "gothit" animation clip (using legacy animations).

Here are the code snippets, the first is for the collision:

void OnTriggerEnter (Collider other)
{       
     if(other.gameObject.CompareTag ("dmgEnvironment")||other.gameObject.CompareTag ("dmgPlayerHit"))
    {
        GetComponent<Animation>().Play("gothit", PlayMode.StopAll);
        GetComponent<Animation>().wrapMode = WrapMode.Once;
        print("hit damage");
    }
}

The attack animation call:

public void AnimatePunch()
{
    DidAttack ();
    //play animation
    if (canHit && lastAttackTime < lastAttackButtonTime + attackTimeout) {
        SendMessage("DidAttack", SendMessageOptions.DontRequireReceiver);
    }
    GetComponent<Animation>().Play("punch", PlayMode.StopAll);
    GetComponent<Animation>().wrapMode = WrapMode.Once;
}

The problem I'm running into is that the "gothit" sequence won't play on collision but will do so when wired to the AnimatePunch().

I'm not sure why this is happening. Any help is greatly appreciated.

\$\endgroup\$
0
\$\begingroup\$

It's a fairly simple fix...just had to add animation speed & it worked.

\$\endgroup\$
  • \$\begingroup\$ Can you provide more information about this solution? \$\endgroup\$ – Kelly Thomas Sep 6 '15 at 9:12
  • \$\begingroup\$ Not really sure what was going on, but I had to add GetComponent<Animation>()["gothit"].speed = 3.5f; to make it work \$\endgroup\$ – Mark Laurel Sep 6 '15 at 15:44
  • \$\begingroup\$ You probably should mark it as answer. \$\endgroup\$ – Maxim Kamalov Sep 8 '15 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.