如何检查对象碰撞器是否正在接触 Unity 3D(除了 oncollisionenter)

问题描述 投票:0回答:1

我有一个合并脚本,他们几乎有一个小、中、大、更大的枚举,当他们触摸时,我的脚本几乎检查它们是否是相同的类型,如果是,则它使 Y 位置较高的那个处于非活动状态,并使那个处于活动状态与放大/更改材料合并为新类型,例如,小型会变成中型,如果一个小型继续生成,最终您会得到例如 3 个介质相互接触并且不会被处理,我认为这是因为我正在处理其他东西并阻止更多碰撞其他的物体是否发生碰撞(如果它们同时接触,则防止 3 个小物体合并),为了解决这个问题,我有 5 个生成器,它们将所有物体生成到一个容器中,所以可以说,有一个中型物体和一个小物体接触,然后一个小的一个击中另一个小的,它会变成中的,但由于仍然接触,它不会触发碰撞调用,这是我的代码:

here you see them touching and not merging again they will only merge if move and triggered again

https://pastebin.com/5J3sjCHx

这是点击时最初调用的地方

private void OnCollisionEnter(Collision collision)
    {
        if(this.ObjectType == ObjectSize.Bigger) { return; }
 
 
        var ObjectCollidedWith = collision.gameObject.GetComponent<MergeableObject>();
        if (ObjectCollidedWith)
        {
            CollisionCheck(ObjectCollidedWith);
        }
    }`



expect everything to merge even if they are touching the same types, not sure if istouching is possible,
i do not want the same types to just be touching i want them to merge again afterwards
c# unity-game-engine unityscript
1个回答
0
投票

使用

OnCollisionStay()
代替
OnCollisionEnter()

© www.soinside.com 2019 - 2024. All rights reserved.