检测玩家与粒子的碰撞 - Unity

6

我刚刚制作了一个粒子系统,每1秒产生一次"熔岩"粒子(大小、颜色等各不相同)。 我需要在玩家与其中一个熔岩粒子碰撞时重新生成respawn()函数已经存在并起作用,现在只需要在正确的时间调用它)。我在Unity Answers和其他网站上进行了相当多的研究,还查看了Stack Overflow,但是我不知道如何做到这一点。

以下是当前粒子系统的截图。我启用了触发器复选框,并尝试更改了一些设置,但没有成功:

enter image description here

当玩家触碰到熔岩粒子时应该调用此代码

private void OnParticleCollision(GameObject collision)
{
    if (collision.CompareTag("Lava"))
    {
        StartCoroutine(TouchedLava());
    }
}

我没有在控制台中收到任何错误信息(即使在运行时)。

提前感谢!

1个回答

6
你需要检查粒子系统中碰撞部分,就在触发器上方,然后将碰撞类型设置为世界。
我认为这个教程可能会对你有帮助:

https://www.youtube.com/watch?v=JRa2g3vgzBo&list=PLX2vGYjWbI0QJJfR-jSqxonYuCHrUhAvN

enter image description here

编辑:

这是我的工作脚本:

public class ParticleTest : MonoBehaviour
{
    public ParticleSystem part;

    void Start()
    {
        part = GetComponent<ParticleSystem>();
    }

    void OnParticleCollision(GameObject other)
    {
        if(other.tag == "Player")
           Debug.Log(other.tag);
    }
}

enter image description here


谢谢你的回答,但是你建议的方法没有起作用。 - Enrico Cortinovis
好的,这是我的工作脚本,以防万一:public class particleTest : MonoBehaviour { public ParticleSystem part;void Start() { part = GetComponent(); } void OnParticleCollision(GameObject other) { if(other.tag == "Player") Debug.Log(other.tag); }} - Raul Moreira de Souza
1
非常感谢你。我不确定在哪里放置带有onParticleCollisionEvent();的脚本,而且在_colliders_部分中使用了3D模式,而我的游戏是2D!所以,感谢你的回答和编辑! :) - Enrico Cortinovis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接