在 OnCollisionExit2D 中请求其他碰撞 - Unity
Asking for other collision inside OnCollisionExit2D - Unity
我有两种标记为 "groundBlack" 和 "groundWhite" 的场地。为了跳跃,我检查对撞机是否留下了一个标签以 "ground".
开头的对象
void OnCollisionExit2D(Collision2D col){
if (col.gameObject.tag.Substring (0, 5) == "ground") {
playerController.grounded = false;
}
}
问题是每次我的播放器从一个移动到另一个时,它都会将 grounded 设置为 false,而我不想这样做。有没有办法知道 OnCollisionExit2D 内部是否仍在与其他标记为地面的对象发生碰撞,或者有另一种方法可以做到这一点?提前致谢!
col.GetContacts
将为您提供所有当前联系人。希望它仍应填充在 OnCollisionExit 中。否则你可以只保留一个冲突列表:在进入时添加,在退出时删除。然后你只在列表为空时将 grounded 设置为 false。
此外,您应该使用 .StartsWith("ground")
而不是 .Substring (0, 5) == "ground"
。无需为了比较而分配新字符串。
我有两种标记为 "groundBlack" 和 "groundWhite" 的场地。为了跳跃,我检查对撞机是否留下了一个标签以 "ground".
开头的对象void OnCollisionExit2D(Collision2D col){
if (col.gameObject.tag.Substring (0, 5) == "ground") {
playerController.grounded = false;
}
}
问题是每次我的播放器从一个移动到另一个时,它都会将 grounded 设置为 false,而我不想这样做。有没有办法知道 OnCollisionExit2D 内部是否仍在与其他标记为地面的对象发生碰撞,或者有另一种方法可以做到这一点?提前致谢!
col.GetContacts
将为您提供所有当前联系人。希望它仍应填充在 OnCollisionExit 中。否则你可以只保留一个冲突列表:在进入时添加,在退出时删除。然后你只在列表为空时将 grounded 设置为 false。
此外,您应该使用 .StartsWith("ground")
而不是 .Substring (0, 5) == "ground"
。无需为了比较而分配新字符串。