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\$

1 Answer 1

0
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ Can you provide more information about this solution? \$\endgroup\$ Sep 6, 2015 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\$
    – junji
    Sep 6, 2015 at 15:44
  • \$\begingroup\$ You probably should mark it as answer. \$\endgroup\$ Sep 8, 2015 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .