检测碰撞动画事件
本文关键字:事件 动画 碰撞 检测 | 更新日期: 2023-09-27 18:02:21
我有一个摇摆剑的动画剪辑。在一个特定的帧,我添加了Event。我希望当玩家挥动剑时,在这种情况下只有敌人会死。
所以我添加了以下OnTriggerEnter
Code
void OnTriggerEnter(Collider col)
{
hit = true;
if (hit)
{
if (col.GetComponent<Collider>().tag == "enemy")
{
Destroy(col.gameObject);
}
}
}
当我尝试添加OnTriggerEnter函数(在动画剪辑中)作为动画事件时,它要求我传递Collider参数,这是我无法添加的。
下面是Add Event
的屏幕截图请帮助我,我如何添加事件与碰撞器(作为参数)在一个特定的帧..由于
Collision
和Trigger
事件在每一帧中各自被调用。
从动画事件中为你的任务调用另一个公共方法,并在那里放置必要的Boolean
或Enum
来控制碰撞,在摆动剑后触发。
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);
}
}
}