我有摇摆剑的动画剪辑。在特定的框架中,我添加了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
请帮帮我,如何在特定帧处添加带碰撞器(作为参数)的事件..谢谢
答案 0 :(得分:0)
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);
}
}
}