- Home /
'Player' AnimationEvent 'impact' has no receiver!
Hello, the console shows me this bug "'Player' AnimationEvent 'impact' has no receiver! Are you missing a component?" while im trying to hit the enemy, what is wrong over here? Just a while ago everything were fine, and now im looking for one thing for hours.Here's the code:
using UnityEngine;
using System.Collections;
public class Player : Creature
{
public static Transform opponent;
public static bool isAttacking;
public static Player player;
Animation animation;
public AnimationClip attackAnimation;
public float attackImpact;
void Awake ()
{
player = this;
initAnimations ();
isAttacking = false;
}
void initAnimations()
{
animation = GetComponent<Animation>();
AnimationEvent attackEvent = new AnimationEvent ();
attackEvent.time = attackImpact;
attackEvent.functionName = "impact";
attackAnimation.AddEvent(attackEvent);
}
void Impact()
{
opponent.GetComponent<Enemy>().GetHit(damage);
}
void Update ()
{
Attack ();
}
protected override void Attack()
{
if (Input.GetKeyUp (KeyCode.Space))
{
if(opponent != null && Vector3.Distance(opponent.position, transform.position)<range)
{
isAttacking=true;
animation.CrossFade(attackAnimation.name);
}
}
if (!animation.IsPlaying (attackAnimation.name))
isAttacking = false;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613201137im_/https://answers.unity.com/themes/thub/images/avi.jpg)