我试图让我的玩家忽略与我所拥有的平台上的边缘对撞机的碰撞。
这是我添加到播放器的脚本
public class TestMovement : MonoBehaviour
{
public Rigidbody2D ball;
private GameObject purplePlat1;
private GameObject player;
// Start is called before the first frame update
void Start()
{
purplePlat1 = GameObject.Find("purple_plat");
player = GameObject.Find("circle-png-44659");
ball = GetComponent<Rigidbody2D>();
ball.AddForce(new Vector2(0, 10), ForceMode2D.Impulse);
Debug.Log("start");
}
// Update is called once per frame
void Update()
{
}
void OnCollisionEnter2D(Collision2D collision)
{
Physics2D.IgnoreCollision(purplePlat1.GetComponent<EdgeCollider2D>
(), GetComponent<CircleCollider2D>());
Debug.Log("collision");
}
}
球还在击中平台。我已经确认oncollisionenter方法正在开火。
您可以使用Unity的layer系统来避免两者之间的collisions。为玩家设置一个图层,为边缘设置另一个图层并取消它们之间的碰撞。