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.