Unity中解决碰撞无法检测问题

Unity中解决碰撞无法检测问题

Unity版本2021.3.21


问题描述

提示:这里描述项目中遇到的问题:

Unity中两物体碰撞后,没有执行碰撞检测内的代码

在这里插入图片描述
在这里插入图片描述
两个物体的组件都是齐全的
代码也没有问题

@Override
	private void OnCollisionEnter(Collision collision)
    {
    
    
        Debug.Log(collision.gameObject.name);

        if (collision.gameObject.name == "Gemstones3")
        {
    
    
            Debug.Log("Pengzhuang");
            gemstones3.SetActive(true);
        }

        if (collision.gameObject.name == "Gemstones4")
            gemstones4.SetActive(true);
    }

解决方案:

最后看了一下Project Setting界面中的Physics,发现里面碰撞的层级没有勾选
在这里插入图片描述
将红框内的勾选上,就正常了

猜你喜欢

转载自blog.csdn.net/weixin_50617270/article/details/128284667