本文介绍了OnCollisionEnter 未统一调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎检查了每个答案,但这些大多是简单的错误和错误.我的问题是即使与其他刚体碰撞时也不会调用 OnCollisionEnter.

I checked nearly every answer for this, but those were mostly simple errors and mistakes.My problem is that OnCollisionEnter is not called even when colliding whith other rigidbody.

这里是没有被调用的部分:

here is the part what does not get called:

 void OnCollisionEnter(UnityEngine.Collision col) {
        Debug.Log("collision!!!");
        foreach(ContactPoint contact in col.contacts) {
            //checking the individual collisions
            if(contact.Equals(this.target))
            {
                if(!attacking) {
                    Debug.Log("hitting target");
                } else {
                    Debug.Log("dying");
                    //engage death sequence
                }
            }
        }
    }

甚至不是碰撞!!!"消息出现.是我理解错误,还是我忘记了什么?

Not even the "collision!!!" message appears. Do I understand the usage wrong, or did I forget something?

推荐答案

您是否在使用 2D 对撞机和刚体?如果是这样,请使用此函数而不是 OnCollisionEnter

Are you using 2D colliders and rigidbodies? If so use this function instead of OnCollisionEnter

void OnCollisionEnter2D(Collision2D coll)
    {
        Debug.Log(coll.gameObject.tag);

    }

这篇关于OnCollisionEnter 未统一调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 11:17