【问题标题】:OnParticleCollision doesn't get triggered in Unity 2018.2在 Unity 2018.2 中不会触发 OnParticleCollision
【发布时间】:2018-08-11 23:36:57
【问题描述】:

在 Untiy 2018.2.2 中加载我的 Unity 2018.1.1 项目后,OnParticleCollision 方法根本不会被触发。在 Unity 2018.1.1 中一切正常。
没有关于更新粒子碰撞的官方信息。

这是我的 Enemy 脚本的 C# 代码。
Player GameObject 具有用作武器的粒子系统 + Collision 模块已启用并已正确设置为与 Enemies 层发生碰撞。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
    // Enemy health
    private int health = 100;

    // !!! Doesn't get triggered at all !!!
    // When the player's weapon hits the Enemy
    private void OnParticleCollision(GameObject other)
    {
        Debug.Log(other.tag);

        if (other.tag == "Weapon")
        {
            // Reduce health
            health -= 50;
            if (health <= 0)
            {
                // Disable the Enemy that was just killed
                gameObject.SetActive(false);
            }
        }
    }
}

【问题讨论】:

  • 选择粒子系统,确保 Collison 模块已启用。现在确保它的 "Send Collision Messages" 也已启用。
  • 是的,它已启用。正如我上面提到的,Unity 2018.1.1 中的一切都完美无缺
  • 检查游戏对象是否仍有“武器”标签。有时会发生在版本升级之间,游戏对象标签丢失。

标签: unity3d


【解决方案1】:

我解决了。
在我的 Enemy 预制件的 Collider 组件中检查了“Is Trigger”。出于某种原因,它在 2018.1 中以任一方式工作,并且仅在 2018.2 中未选中“Is Trigger”的情况下工作。
万一您遇到同样的问题,只需取消选中 GameObjects 上的“Is Trigger”,一切都会正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多