The problem I think I’m having is that my animation events need to be triggered when one of the enemy’s fists (or legs) collide with the player’s armature, but the animator component is on the main part of the enemy’s body.
I can’t be the only person who’s had this problem, so what’s the general work-around?
Since no one replied after all this time, I guess I didn’t give enough information. I’ll try to give more. If it’s too much of a wall of text, bear with me. Please.
Basically each function I call on an animation clip on an enemy armature either takes a bool which indicates that part of the body is in a damageable part of the animation… and the function either true or false. So, for example, when the enemy begins winding up their left arm for a punch, I make the bool “Hitbyleftarm” false. When it finishes winding up and is in the punching part of the animation, I make it true. This script is on the main gameobject, with the animator component on it. Here’s one of the functions.
public void HitbyLeftleg ()
{
hitbyleftleg = true;
}
I’ve got a script called “hitplayer” which most of the code takes place in an OnCollisionEnter section. The same script is on the hands and the feet. It takes the bool of the previous function, and if it’s true, and the gameobject that’s hitting is named the same as the bool would work on, it damages the player. Here’s an excerpt of the script, which is neither the beginning nor the end of it.
The code goes something a little like this. This is an excerpt, not the full code. It’s just for the first body part in the script.
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Player1")
{
if (gameObject.name == "D1LeftHandCollider")
{
if (demonai.hitbyleftarm == true)
{
(other.transform.root.GetComponent(typeof(anim)) as anim).hitbydem1();
}
}
I name the function for the function section of the event for the in the imported animations panel hitbyLegtleg No object or variables are entered.
the error is, during runtime when the event is called:
‘d1LeftFoot’ AnimationEvent ‘hitbyRightarm’ has no receiver! Are you missing a component?
The error message means that there is no component containing a function called “hitByRightarm” on the object that has the Animator. All methods for events must be on the GameObject that has the Animator component. The event system, at least to my knowledge, does not traverse the children of the GameObject that has the Animator to see if any descendants have that method.