下面是报错的代码,主要是想监听碰撞的物体,但是我在另一个ts文件写代码时用boxCollider2D却不会报错,用circleCollider2D却会。
start() {
// 获取碰撞事件得物理形状
this.circleCollider2D = this.football.getComponent(CircleCollider2D);
this.circleCollider2D.on(Contact2DType.BEGIN_CONTACT, this.OnBeginContact, this);
}
onDestroy() {
this.circleCollider2D.off(Contact2DType.BEGIN_CONTACT, this.OnBeginContact, this);
}
// 碰撞检测
OnBeginContact(self, other): void {
if (other.node._name == "player") {
console.log("碰到足球啦");
}
}
