C# 碰撞2D。i触摸(其他碰撞器)不工作

C# 碰撞2D。i触摸(其他碰撞器)不工作,c#,unity3d,C#,Unity3d,因此,出于某种原因,“rWallCollider.IsTouching(lWallCollider)”条件没有响应。我在同一个项目中遇到了同样的问题,但我想不起来我是怎么解决的。。。顺便说一句,我已经指定了对撞机 using UnityEngine; public class GameManager : MonoBehaviour { bool gameHasEnded = false; public Collider2D rWallCollider; public C

因此,出于某种原因,“rWallCollider.IsTouching(lWallCollider)”条件没有响应。我在同一个项目中遇到了同样的问题,但我想不起来我是怎么解决的。。。顺便说一句,我已经指定了对撞机

using UnityEngine;

public class GameManager : MonoBehaviour
{
    bool gameHasEnded = false;
    public Collider2D rWallCollider;
    public Collider2D lWallCollider;


    void Update()
    {
        if (rWallCollider.IsTouching(lWallCollider))
        {
            EndGame();
        }
    }

    public void EndGame ()
    {
        if (gameHasEnded == false)
        {
            gameHasEnded = true;
            Debug.Log("End game!");
        }
    }

}

谢谢你抽出时间

也请分享一些关于这些对撞机的细节。(碰撞器的类型,配置参数,它们应该接触的位置,但效果不会触发,等等)我猜你忘了给一个或两个对象添加刚体了吧?