检测动画事件中的碰撞

时间:2016-08-13 18:26:07

标签: c# unity3d

我有摇摆剑的动画剪辑。在特定的框架中,我添加了Event。我想要当玩家摆动剑,在这种情况下只有敌人可以死。

所以我添加了以下OnTriggerEnter代码

void OnTriggerEnter(Collider col)
{
        hit = true;
        if (hit)
        {
            if (col.GetComponent<Collider>().tag == "enemy")
            {
                Destroy(col.gameObject);
            }
        }
}

当我尝试将函数OnTriggerEnter(在动画片段中)添加为动画事件时,它要求我传递Collider参数,我无法添加。

Here is the screen shot of Add Event

请帮帮我,如何在特定帧处添加带碰撞器(作为参数)的事件..谢谢

1 个答案:

答案 0 :(得分:0)

CollisionTrigger事件会在每个帧上自行调用。

从动画事件中为你的任务调用另一个公共方法,并在那里放置必要的BooleanEnum来控制碰撞,在摆动剑后触发。

public void SwingingSword()
{
 isSwingingSword = true; // make it false when not swinging the sword.
}

void OnTriggerEnter(Collider col)
{
  hit = true; // not sure what it's job here

  if (isSwingingSword && hit)
  {
   if (col.GetComponent<Collider>().tag == "enemy")
   {
    Destroy(col.gameObject);
   }
  }
}